很难说我怎么了,但是我想在这里:
SELECT name
, (SELECT count(age) as count)
FROM 'students'
WHERE class = '1c'
;
SELECT name
, (SELECT count(age) as count)
FROM 'students'
WHERE class = '2b'
它们是2个独立的mysql语句,所以我该如何计算一个语句 显示类似的内容:
+--------+-------+
| name | count |
+--------+-------+
| Peeter | 5 |
| Harry | 3 |
+--------+-------+
答案 0 :(得分:1)
您可以在下面尝试-使用group by
和operator
SELECT name, count(age) as count
FROM 'students'
WHERE class in ('1c','2b')
group by name