gpt4 book ai didi

sql - 使用 group by 查找计数

转载 作者:行者123 更新时间:2023-12-04 13:28:16 26 4
gpt4 key购买 nike

我有一个学生表如下

Rajesh Kumar
Nagendra Prasad
Bharath kumar
Raghav Kumar
Abhnav Bindhra

我需要编写一个查询,该查询将计算姓名为“kumar”和“Prasad”的学生人数。
Kumar   3
Prasad 1

我怎么做?我尝试了以下查询,但我怀疑 groupby 子句的位置?
 Select Name,count(Name) from Student where 
Name LIKE ('%Kumar%')
or Name LIKE ('%Prasad%')
group by ???

最佳答案

select  FindName 
, count(*)
from (
select case
when Name like '%Kumar%' then 'Kumar'
when Name like '%Prasad%' then 'Prasad'
end as FindName
from Student
) as SubQueryAlias
where FindName is not null
group by
FindName

关于sql - 使用 group by 查找计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17293688/

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