【问题标题】:Hey folks, I'm new in sqlite and I got stuck on a training question嘿伙计们,我是 sqlite 的新手,我被困在一个培训问题上
【发布时间】:2021-03-21 09:38:27
【问题描述】:

数据库如下:

我想要得到的输出是:

我的sql查询是这样的,得到的输出是这样的。

SELECT score as "0-25" , COUNT(*) FROM Gamer WHERE (score > 0 and score<25)
UNION 
SELECT score as "26-50", COUNT(*) FROM Gamer WHERE (score > 26 and score<50)
UNION 
SELECT score as "51-75", COUNT(*) FROM Gamer WHERE (score > 51 and score<75)
UNION 
SELECT score as "76-100", COUNT(*) FROM Gamer WHERE (score > 76 and score<=100)

【问题讨论】:

  • 您有问题吗?

标签: sql sqlite count pivot


【解决方案1】:

您使用条件聚合。在 SQLite 中:

select 
    sum(score between  0 and  25) as s_00_25,
    sum(score between 26 and  50) as s_26_50,
    sum(score between 51 and  75) as s_51_75,
    sum(score between 76 and 100) as s_76_100
from gamer

【讨论】:

    猜你喜欢
    • 2021-11-20
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 2021-09-05
    • 2020-07-14
    • 2021-05-08
    • 2018-08-09
    • 2022-07-28
    相关资源
    最近更新 更多