我有一张桌子
SKU COUNT
A 2
A 2
A 2
B 2
B 1
C 3
C 3
C 3
我想返回计数不同的SKU
这是针对Oracle数据库的SQL查询
Return SKU COUNT
B 2
B 1
答案 0 :(得分:1)
尝试一下:
select sku, count(distinct count)
from my_table
group by sku
having count(distinct count) > 1
答案 1 :(得分:0)
一种简单的方法使用exists
:
select t.*
from t
where exists (select 1 from t t2 where t2.sku = t.sku and t2.count <> t.count);
答案 2 :(得分:0)
您可以使用子查询来查找草图。例如:
select *
from t
where sku in (select sku from t group by sku having min(count) <> max(count))
答案 3 :(得分:0)
您可以使用count(distinct count)来托盘
select sku, count, count(distinct count)
from my_table
group by sku, count
having count(distinct count) > 1