doujin8673 2014-11-05 12:12
浏览 37

选择具有相似名称的行

So I have a tbl_total like this.

Name   | Total  |  Month
=========================
David  | 87     | Jan
Mike   | 67     | Jan
David  | 90     | Feb
Mike   | 100    | Feb

And I want to display it like this. Could please someone tell me how to do this coz i've no idea at all how to display like this in PHP.

Name   | Jan | Feb
===================
David  | 87  | 90
Mike   | 67  | 100
  • 写回答

2条回答 默认 最新

  • dougu4027 2014-11-05 12:15
    关注
    select name,
           sum(case when month = 'Jan' then total else 0 end) as Jan,
           sum(case when month = 'Feb' then total else 0 end) as Feb,
           sum(case when month = 'Mar' then total else 0 end) as Mar,
           sum(case when month = 'Apr' then total else 0 end) as Apr,
           sum(case when month = 'May' then total else 0 end) as May,
           sum(case when month = 'Jun' then total else 0 end) as Jun,
           sum(case when month = 'Jul' then total else 0 end) as Jul,
           sum(case when month = 'Aug' then total else 0 end) as Aug,
           sum(case when month = 'Sep' then total else 0 end) as Sep,
           sum(case when month = 'Oct' then total else 0 end) as Oct,
           sum(case when month = 'Nov' then total else 0 end) as Nov,
           sum(case when month = 'Dec' then total else 0 end) as `Dec`
    from your_table
    group by name
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?