Monday 3 September 2018

Mysqli query does not work

I want to retrieve all the maximum disease use in an year.I have a table named view_accepted_appoinments which has column disease and date. I am trying this query but it is not working

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;

The query returns this which gives wrong disease name
+--------------+------+-------+
| disease      | YEAR | count |
+--------------+------+-------+
| Primary Care | 2014 |     8 |
| Primary Care | 2013 |     1 |
+--------------+------+-------+


 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;

0 comments:

Post a Comment