gpt4 book ai didi

mysql - 如何选择两列不等于值的行?

转载 作者:可可西里 更新时间:2023-11-01 07:50:50 27 4
gpt4 key购买 nike

我有一个表格,其中每一行都有一个类别子类别

我想选择除特定 categorysubcategory 以外的所有行。

我的数据是这样的:

| category | subcategory |
|----------|-------------|
| Color | Orange |
| Fruit | Apple |
| Fruit | Orange |
| Fruit | Banana |

我希望我的结果看起来像这样:

| category | subcategory |
|----------|-------------|
| Color | Orange |
| Fruit | Banana |

这是我试过但显然行不通的方法:

SELECT *
FROM table
WHERE
(category <> 'Fruit' AND subcategory = 'Orange') and
(category <> 'Fruit' AND subcategory = 'Apple')

我似乎无法思考如何让它发挥作用。 SQL 是否有办法说 where not (this and this) 因为我仍然想要“Fruit”类别并且我仍然想要“Orange”子类别。

最佳答案

那为什么不试试 NOT 呢?

SELECT *
FROM yourtable
WHERE NOT (category = 'Fruit' AND subcategory IN ('Orange', 'Apple'))

关于mysql - 如何选择两列不等于值的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053201/

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