我被一个愚蠢的新手问题弄糊涂了!我试图在sqlite中编写一个命令,只显示选定列中具有唯一值的行。举个例子:
Product | Price Cheese | 5 Yogurt | 2 Milk | 2 Soy Milk | 3
我希望结果是
Cheese Soy Milk
我想答案很简单。有人能帮帮我吗?
e5nszbig1#
你可以用 not exists :
not exists
select t.* from t where not exists (select 1 from t t2 where t2.price = t.price and t2.product <> t.product);
或者,聚合:
select max(product) from t group by price having count(*) = 1;
3vpjnl9f2#
使用以下命令尝试 IN ```selectproductfrom yourTablewhere price not in(selectpricefrom yourTablegroup bypricehaving count(*) > 1)
IN
2条答案
按热度按时间e5nszbig1#
你可以用
not exists
:或者,聚合:
3vpjnl9f2#
使用以下命令尝试
IN
```select
product
from yourTable
where price not in
(
select
price
from yourTable
group by
price
having count(*) > 1
)