在QUERY中选择COUNT TROUBLE

时间:2017-09-18 08:30:24

标签: mysql sql

嗨,我只需要简单的QUERY - MYSQL FOR MY DASHBOARD。使用线条图和区域图.. enter image description here

Citizentable

  1. citizenid
  2. citizenencensusyear(censusyeartable的fK)
  3. citizengender
  4. censusyeartable

    1. censusyearid
      1. censusyear
    2. 预期产出:

      1. censusyear
      2. 男性
      3. totalfemale
      4. 我几乎无法弄清楚如何获得确切的价值..

        CAN ANYBODY可以帮助我

1 个答案:

答案 0 :(得分:0)

我认为您需要这样的查询:

select  
censusyear,
sum(case CitycenGender when 'Male' then 1 else 0 end) as 'Total Male',
sum(case CitycenGender when 'Female' then 1 else 0 end) as 'Total Male'
from CitycenTable
inner join CensusYearTable on CityCensusYear = CensusYearID

问候。