Sql 仅计算非重复值
我需要一个查询来只计算不重复的值,有没有办法在没有子查询或临时表的情况下做到这一点 如果我有这样一张桌子:Sql 仅计算非重复值,sql,count,Sql,Count,我需要一个查询来只计算不重复的值,有没有办法在没有子查询或临时表的情况下做到这一点 如果我有这样一张桌子: +------------+----------+ | item_name |quantity | +------------+----------+ | Calculator | 89 | | Notebooks | 40 | | Pencil | 40 | | Pens | 32 | | Shirts |
+------------+----------+
| item_name |quantity |
+------------+----------+
| Calculator | 89 |
| Notebooks | 40 |
| Pencil | 40 |
| Pens | 32 |
| Shirts | 29 |
| Shoes | 29 |
| Trousers | 29 |
+------------+----------+
我不能使用SELECT COUNT(不同数量),因为它返回4<代码>(89 | 40 | 32 | 29)
我怎样才能返回2<代码>(89 | 32)使用子查询:
select count(*)
from (select quantity, count(*) as cnt
from t
group by quantity
) x
where cnt = 1;