我想创建一个表格,其中包含多年的行和3列,其中的值是每年收入低于500k,500k到1M,大于1M的项目数。我被告知尝试案件判决,但我真的无法完成它。我使用的是mysql
我的字段是financialYear,AdjRevenue1Y来自financials_tbl。
我的目标是只获得3列(年份,500以下,500至1M之间)
select fiscalYear,
Case
When AdjRevenue1YCommited < 500000 then count(AdjRevenue1YCommited)
Else null
end as b500,
Case
When AdjRevenue1YCommited between 500000 and 1000000 then count(AdjRevenue1YCommited)
Else null
end as a500
from financials_tbl
group by fiscalYear
答案 0 :(得分:1)
试试这个:
select fiscalYear,
sum(AdjRevenue1YCommited < 500000) as b500,
sum(AdjRevenue1YCommited between 500000 and 1000000) as a500
from financials_tbl
group by fiscalYear