gpt4 book ai didi

MySQL OR AND 语法

转载 作者:行者123 更新时间:2023-11-29 07:51:49 24 4
gpt4 key购买 nike

刚刚开始学习 MySQL,这是一个菜鸟问题,也是我在 StackOverflow 上的第一个问题。

假设我有 12 个订单状态,我想从其中的 5 个中选择总计。我会使用:

SELECT SUM(total) AS total FROM `orders` WHERE 
order_status_id = '1' OR
order_status_id = '2' OR
order_status_id = '5' OR
order_status_id = '9' OR
order_status_id = '12';

有没有更短的方法来实现这个?类似...

SELECT SUM(total) AS total FROM `bd_order` WHERE
order_status_id = ('1' OR '2' OR '5' OR '9' OR '12');

最佳答案

您可以使用IN

SELECT SUM(total) AS total 
FROM `bd_order`
WHERE order_status_id in (1,2,5,9,12);

关于MySQL OR AND 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205663/

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