gpt4 book ai didi

mysql - 我想根据 where 子句在不同列上显示一列数据总和

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

下面是描述我的要求的图片我有一个包含不同数据的列我希望它在数据= 1作为col1和数据= 2作为col2的条件下计数等等....

Below is image which describe my requirements i have a column having different data i want its count on where condition where data=1 as col1 and where data = 2 as col2 and so on....

最佳答案

SELECT
COUNT(CASE data WHEN 1 THEN 1 ELSE NULL END) as Col1,
COUNT(CASE data WHEN 2 THEN 1 ELSE NULL END) as Col2,
COUNT(CASE data WHEN 3 THEN 1 ELSE NULL END) as Col3,
COUNT(CASE data WHEN 4 THEN 1 ELSE NULL END) as Col4
FROM yourTable

关于mysql - 我想根据 where 子句在不同列上显示一列数据总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24369293/

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