Mysqli查询不起作用

时间:2014-12-13 16:57:07

标签: mysql

我想检索一年内所有最大的疾病使用情况。我有一个名为view_accepted_appoinments的表,它有列疾病和日期。我正在尝试此查询,但它无法正常工作

select distinct doc_specilization as disease,
DATE_FORMAT(date,'%Y') as year,
count(Distinct doc_specilization) as count
from view_accepted_appoinments
group by year
order by year desc; 

查询返回此错误的疾病名称

+--------------+------+-------+
| disease      | YEAR | count |
+--------------+------+-------+
| Primary Care | 2014 |     8 |
| Primary Care | 2013 |     1 |
+--------------+------+-------+

2 个答案:

答案 0 :(得分:0)

尝试

SELECT doc_specialization AS disease,
DATE_FORMAT(date, '%Y') AS year,
COUNT(doc_specialization) AS count,
FROM view_accepted_appoinments
GROUP BY doc_specialization, year
ORDER BY year DESC, doc_specialization ASC;

答案 1 :(得分:0)

 select distinct d , spec,c from(
      select date_format(date,"%Y") as d,
      doctor, doc_specilization as spec,
      count(doc_specilization) as  c from
      view_accepted_appoinments
      group by doc_specilization, d)f
      group by d;