【问题标题】:SELECT COUNT TROUBLE IN QUERY [closed]在查询中选择计数问题[关闭]
【发布时间】:2018-02-26 17:26:45
【问题描述】:

您好,我只需要简单的查询 - 我的仪表板的 MYSQL。使用折线图和面积图..enter image description here

公民身份

  1. 公民
  2. citizencensusyear(人口普查年表的 fK)
  3. 公民性别

人口普查年表

  1. censusyearid
    1. 人口普查年

预期输出:

  1. 人口普查年
  2. 男性总数
  3. 总女

我只是不知道如何获得确切的价值..

谁能帮帮我

【问题讨论】:

  • 拿出真正的 mysql 表和你的东西
  • 先生,那是我表的确切列
  • 的确切值?
  • 我有 Citizentable 列 CitizenID、CitizenGender、CitizenCensusYear 一个 censusyeartable 与 censusyearid 和 censusyear 我需要输出 CensusYear 总男性总女性 2016 25 24 2017 21 21 2018 11 11
  • 问题绝对告诉我们--------

标签: mysql sql


【解决方案1】:

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

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

问候。

【讨论】:

  • 非常感谢我没有弄明白,我什至想到了从选择语句中进行选择。谢谢先生。
  • 不客气 ;)
猜你喜欢
  • 1970-01-01
  • 2011-07-27
  • 2020-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多