Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 仅计算非重复值_Sql_Count - Fatal编程技术网

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;