gpt4 book ai didi

mysql - 查询我的 sql 数据库

转载 作者:行者123 更新时间:2023-11-29 01:53:25 25 4
gpt4 key购买 nike

我有两个不同的查询:

SELECT Nazione,
count(*) as Gold
FROM `SummerTotalMedal`
where Medaglia = 'gold'
and Sport = 'Athletics'
group by Nazione
order by Gold DESC

SELECT Nazione, 
count(*) as Silver
FROM `SummerTotalMedal`
where Medaglia = 'silver'
and Sport = 'Athletics'
group by Nazione
order by Silver DESC

有没有办法加入这个查询,以便我在两个不同的列上得到两个不同的输出?

最佳答案

您可以使用相同的条件聚合

select 
Nazione,
sum(case when Medaglia ='gold' and Sport='Athletics' then 1 else 0 end) as Gold,
sum(case when Medaglia ='silver' and Sport='Athletics' then 1 else 0 end) as Silver
from SummerTotalMedal
group by Nazione

关于mysql - 查询我的 sql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35226390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com