【问题标题】:Complex Mysql query grouping columns [duplicate]复杂的Mysql查询分组列[重复]
【发布时间】:2018-08-12 19:30:23
【问题描述】:

我有一张像上面这样的桌子。我需要像下面这样使用Mysql 查询。

【问题讨论】:

  • 我试过SELECT emp_name,count(attendance) FROM testwhere attendance='present' GROUP by emp_name。但这不是我想要的。
  • 这个问题已经被回答了很多次了。在发布问题之前,请花一些时间研究该网站以获得相关答案。

标签: mysql


【解决方案1】:

你可以使用条件聚合来计算结果,

SELECT EMP_NAME,
       SUM(attendance = 'Present')  AS `No of Present`,
       SUM(attendance = 'Absent')  AS `No of Absent`
FROM tableName
GROUP BY EMP_NAME

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    相关资源
    最近更新 更多