我在计算数据库中的某些条目时遇到了一些问题。
我有以下查询:
SELECT ref_training_date, training_date FROM fynslund.users_training
INNER JOIN training
ON training.id = users_training.ref_training_date
WHERE attendance = 1
这给了我以下结果:
┌──────┬───────────────┐ │ ID │ DATE │ ├──────┼───────────────┤ │ '55' │ '2018-01-09' │ │ '55' │ '2018-01-09' │ │ '54' │ '2018-02-03' │ │ '54' │ '2018-02-03' │ │ '54' │ '2018-02-03' │ │ '54' │ '2018-02-03' │ └──────┴───────────────┘
如何计算ID为'55'
的日期显示的次数?
答案 0 :(得分:0)
您需要GOUP BY ref_training_date
然后COUNT(training_date)
:
SELECT ref_training_date, COUNT(training_date) AS date_count
FROM fynslund.users_training
INNER JOIN training ON training.id = users_training.ref_training_date
WHERE attendance = 1
GROUP BY ref_training_date