nidafg 2012-02-22 11:03 采纳率: 0%
浏览 257
已采纳

Mysql 查询问题

   表格里有如下几个字段:
            date       business   province   income    newuser
       2012-01-02     game1       北京        200       20
       2012-01-03     game1       北京        100       20
       2012-01-02     game2       北京        300       20
       2012-01-03     game3       北京        200       20
       2012-01-02     game4       北京        200       20
        xxxxxxx       xxxxx       xxx       xxx       xx

   最初是要在表格里体现每一天,每个省的所有业务的总收入和新增用户数,所以我直接写select date,province,SUM(income),sum(newuser) from table group by date,province 就行了,现在又有新的两个字段要查询,要在原有的查询出来的一条记录的基础上加两列,查出特定的几个游戏的sum(income)和sum(newuser),也是按每一天每个省算,请问sql语句如何写呢?
  • 写回答

3条回答 默认 最新

  • li28544071 2012-02-22 14:18
    关注

    [code="sql"]select date, province, sum(case when business = 'game1' then income else 0 end) as game1_income,
    sum(case when business = 'game1' then newuser else 0 end) as game1_newuser,
    sum(case when business = 'game2' then income else 0 end) as game2_income,
    sum(case when business = 'game2' then newuser else 0 end) as game2_newuser
    ....
    from 业务数据表 group by date, province[/code]

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog