gpt4 book ai didi

sql - 根据列过滤掉行中的重复项

转载 作者:行者123 更新时间:2023-12-01 08:51:45 25 4
gpt4 key购买 nike

假设我有 2 列:

Fruit Condition
apple unripe
banana ripe
apple ripe
banana moldy
peach moldy
peach ripe
apple ripe
pineapple soldout

我只想知道哪些水果是成熟的还是未成熟的,没有发霉或卖完了(只有苹果)

Select fruit
from example
where (condition <> 'moldy' or condition <> 'soldout')
and (condition = 'ripe' or condition = 'unripe')
group by fruit

不工作

最佳答案

您正在使用 or在一个不是。这是错误的做法。

使用:

where not (condition = 'moldy' or condition = 'soldout')

或使用

where (condition <> 'moldy' and condition <> 'soldout')

那么,我假设您只想要成熟或未成熟的水果。

select distinct Fruit
from Example E1
where Condition in ('ripe','unripe')
and not exists
(
select E2.Fruit
from Example E2
where E1.Fruit = E2.Fruit
and E2.Condition in ('moldy','soldout')
)

关于sql - 根据列过滤掉行中的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39874368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com