我对SQL很陌生,我正在试图弄清楚如何得到这个结果:
Type Number Sold
Detached 5
Semi-detached 2
Terrace 1
Link 8
使用查询,我尝试过:
SELECT SPropertyType AS Type, COUNT (SPropertyCurrentState) AS NumberSold
FROM SaleProperty
WHERE SPropertyCurrentState = 'Sold';
但它给了我一个错误。
答案 0 :(得分:0)
您忘了使用GROUP BY。 使用此:
SELECT
SPropertyType AS Type,
COUNT (SPropertyCurrentState) AS NumberSold
FROM
SaleProperty
WHERE
Upper(SPropertyCurrentState) = 'SOLD'
GROUP BY
SPropertyType;
答案 1 :(得分:-1)
您需要添加group by SPropertyType
子句
最终的SQL将如下所示
SELECT
SPropertyType AS Type,
COUNT (SPropertyCurrentState) AS NumberSold
FROM SaleProperty
WHERE
SPropertyCurrentState = 'Sold'
GROUP BY
SPropertyType;