可以使用一些提供SQL查询的帮助来提取“columna”值,其中最大数字“columnb”值为“Active”。在columnb中有一个值为“Active”的值,我想拉出columna值,该值具有最大值Active n columnb。
我看输出为columna = M1和Count = 4
columna columnb
M1 Active
M1 Active
M1 Active
M1 Active
M2 failed
M2 failed
M2 failed
M3 pending
M3 pending
M3 pending
答案 0 :(得分:1)
您要求的结果将由以下方式生成:
SELECT columna,COUNT(*)
FROM Table
WHERE columnb = 'Active'
GROUP BY columna
答案 1 :(得分:1)
SELECT top 1 columna,COUNT(*) as cnt
FROM Table1
WHERE columnb = 'Active'
GROUP BY columna
order by cnt desc
<强> FIDDLE 强>
答案 2 :(得分:0)
SELECT columna,count(*) FROM TABLE_NAME where columnb = "Active" GROUP BY columna
答案 3 :(得分:0)
RDMBS-es之间的语法略有不同,但逻辑仍然存在。根据{{1}}过滤您的行,按columnb
对其进行分组,在columna
上订购并选择前1
SQL Server:
count(*)
MySQL的:
SELECT TOP 1 columna, COUNT(*) AS Count
FROM YourTable
WHERE columnb = 'Active'
GROUP BY columna
ORDER BY COUNT(*) DESC