Sql Select 不同计数
Sql Select Distint Count
我有一个有趣的情况,我想计算具有变量值的 DISTINCT 行。
想象一下这样的 table:
**Customer City status**
Acme Sydney Exist
Bally Sydney new exist
Bally Melbourne new exist
Costco Melbourne Exist
David Sydney null
Ego Japan Exist
Dave Sydney Exist
我正在寻找这个结果:
按状态分组 "Exist"
**City status**
Sydney 2
Japan 1
Melbourne 1
如何为此结果创建 sql 查询
谢谢
SELECT [City], COUNT(status)
FROM [TABLE_NAME]
WHERE [status] LIKE '%exist%'
GROUP BY [City]
这可能有效。
您正在寻找:
select city, count(*)
from t
where status = 'Exist'
group by city;
我有一个有趣的情况,我想计算具有变量值的 DISTINCT 行。
想象一下这样的 table:
**Customer City status**
Acme Sydney Exist
Bally Sydney new exist
Bally Melbourne new exist
Costco Melbourne Exist
David Sydney null
Ego Japan Exist
Dave Sydney Exist
我正在寻找这个结果: 按状态分组 "Exist"
**City status**
Sydney 2
Japan 1
Melbourne 1
如何为此结果创建 sql 查询
谢谢
SELECT [City], COUNT(status)
FROM [TABLE_NAME]
WHERE [status] LIKE '%exist%'
GROUP BY [City]
这可能有效。
您正在寻找:
select city, count(*)
from t
where status = 'Exist'
group by city;