Bel*_*ita 0 sql oracle count matrix
我是这里的新用户,我认为这太棒了!我需要一些帮助:
我这样做,但不要像我想的那样工作!(count(countOfCat)不好!)
select count(countOfCat) as "Cat", count(countOfDog) as "dog", count(countOfHorse) as "horse", 0 as "duck", 0 as "Mouse"
from animal
where Birthdate in
(...
-- i think not important
...
)
and ( species= 'cat' or species= 'dog' or species= 'horse')
group by species
Run Code Online (Sandbox Code Playgroud)
我想要收到这样的
Cat Dog Horse Duck mouse ------- ------- ------- ------ ------- 1234 2345 3456 0 0
...
我需要所有计数都在同一行.
我不能利用这个
noGood- Cat Dog Horse Duck mouse noGood- ----- ------ -------- ------- ------- noGood- 1234 0 0 0 0 noGood- 0 2345 0 0 0 noGood- 0 0 3456 0 0
谢谢你的时间!
哒!
select sum(case when species = 'cat' then 1 else 0 end) as "Cat",
sum(case when species = 'dog' then 1 else 0 end) as "Dog",
sum(case when species = 'horse' then 1 else 0 end) as "Horse",
0 as "duck",
0 as "Mouse"
from animal
where species in ('cat', 'dog', 'horse')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |