我是mysql的新手,我试图从一个表中获取每年报告的所有问题类型的列表。我想得到:
2014 Network Cable 1
2015年注射失败1
。
2015叉车传感器2
但到目前为止我能得到的是:
SQL:
SELECT DISTINCT *
FROM
(SELECT natureOfProblem, COUNT(*) AS year2014
FROM problem
WHERE dateProblemStarted < '20150101'
GROUP BY natureOfProblem) a,
(SELECT natureOfProblem, COUNT(*) AS year2015
FROM problem
WHERE dateProblemStarted > '20141231'
GROUP BY natureOfProblem)b
GROUP BY a.natureOfProblem, b.natureOfProblem;
答案 0 :(得分:2)
SELECT year(dateProblemStarted), natureOfProblem, count(1)
FROM problem
GROUP BY year(dateProblemStarted), natureOfProblem