我有以下查询:
select exam_id,semester_id from marks where student_id=150 and semester_id<=1914;
它的输出是:
exam_id | semester_id
27 1913
68 1913
64 1914
我想找出类似semester_id的计数.
但我想要这样的输出
semester_id 1913---------->count 2
semester_id 1914---------->count 1
最佳答案
你只需使用GROUP BY:
SELECT semester_id,COUNT(*) as count
FROM marks
WHERE student_id=150
AND semester_id<=1914
GROUP BY semester_id;