我有一个这样的表:
doctor_name | medicine
John a
John b
John a
John b
Kevin c
Kevin c
Kevin c
Kevin a
我想按 doctor_name
和 medicine
进行分组。我想要的输出是像这样SELECT
:
doctor_name | medicine | COUNT(medicine)
John a 2
John b 2
Kevin a 1
Kevin c 3
我不知道如何在 MySQL 中使用普通的 GROUP BY
来做到这一点。如果有人能帮助我,我真的很感激。
最佳答案
您需要按 doctor_name
和 medicine
进行分组
select
doctor_name,
medicine,
count(*) as total
from table_name
group by doctor_name,medicine
关于MySQL - 组中组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161718/