如何使用group by在sql上选择数据

时间:2017-12-07 00:37:29

标签: mysql sql database select

我有桌子 enter image description here

我想选择这样的 enter image description here

如何获取数据count_attendance?

1 个答案:

答案 0 :(得分:0)

您可以使用子查询来执行此操作:

select name, gol, count(attendance) as count_data,(Select count(attendance) from tablename n where n.attendance='yes' and n.name=tablename.name and n.gol=tablename.gol) as count_attendance from tablename group by name,gol

只需将tablename替换为您的表名。