mysql查詢性別命令,根據年紀階段統計人數?
select 性別,case when 年齡 between 20 and 29 then 1 else 0 end [20-29],case when 年齡 between 30 and 39 then 1 else 0 end [30-39],case when 年齡 between 40 and 49 then 1 else 0 end [40-49]from 表名group by 性別以上使用于大部分數據庫只是在起別名上,只適用于sqlserveroracle的話起別名select 性別,case when 年齡 between 20 and 29 then 1 else 0 end "20-29",case when 年齡 between 30 and 39 then 1 else 0 end "30-39",case when 年齡 between 40 and 49 then 1 else 0 end "40-49"from 表名group by 性別mysql的話select 性別,case when 年齡 between 20 and 29 then 1 else 0 end `20-29,case when 年齡 between 30 and 39 then 1 else 0 end `30-39`,case when 年齡 between 40 and 49 then 1 else 0 end `40-49from 表名group by 性別