繁体   English   中英

SQL SELECT 行数相等

[英]SQL SELECT rows where count are equal

我正在尝试通过某些值对 select 一堆行进行查询。 这是我的表的一个例子:

*my_table*
number  item     status
01      hat      on delivery
01      gloves   delivered
01      sock     cancel
02      hat      cancelled
02      gloves   delivered
02      sock     cancelled

我想将所有已交付或取消的值的行发送到存档。 我尝试过这样的事情,

Select *
from my_table
where status = "cancelled" and status = "delivered"

但它没有用。

正如你所说,你应该使用或:

Select *
from my_table
where status = 'cancelled' or status = 'delivered'

主要是因为 status 不能同时具有这两个值。

您必须使用 OR 子句

Select *
from my_table
where (status = 'cancelled' or status = delivered);

如果在有多个 WHERE 子句时使用 or 条件,请确保将其括在括号中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM