dongwuqi4243 2016-10-15 21:03
浏览 102
已采纳

每行的Sqlite总和

I have a database which print me all employees of countries.

 |Year|Country1|Country2|Country3|Country4|All

This is table, only with 25 countries and year from 2000 to now. In Internet I found only information for sum(country4) for example, but how can use sum with all fields exclude Year and All.

Updated:

 Year | ZA | NA | BW | MG | ZW | AO | ZM | KE | NG | CF | GH | CM | CD | ET | UG | EG | DZ | MA | MR | NE | SD | TN | SO | All 
------+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-----
 2000 | 10 | 10 |  5 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 | 0  | 0  |  0 |  25  
 2001 | 25 | 10 |  8 |  5 |  5 |  9 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 |  0 | 0  | 0  |  0 |  62  

This is database and I need the sum from ZA to SO without year and All. All is the result of the sum, but I think SQLite or PHP can build sum without me doing it manually?

When I search in internet I found only example for sum of one column but not for rows.

  • 写回答

2条回答 默认 最新

  • dry18813 2016-10-17 12:52
    关注

    To 'sum a row' you simply add the relevant fields together:

    select
      ZA+NA+BW+MG+ZW+AO+ZM+KE+NG+CF+GH+CM+CD+ET+UG+EG+DZ+MA+MR+NE+SD+TN+SO
    from
      table_name
    

    That results in (from your test data) two rows:

    25
    62
    

    If you want to get the sum of those values just wrap the addition in a sum:

    sum(ZA+NA+BW+MG+ZW+AO+ZM+KE+NG+CF+GH+CM+CD+ET+UG+EG+DZ+MA+MR+NE+SD+TN+SO)
    

    Result:

    87
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!