[英]SELECT sum but with where in MySQL
我正在尝试总结我的orders
表的total_grand
列。
所以我有这个查询
SELECT sum(total_grand) as total
FROM `orders`
WHERE overall_status in ("In-Transit","Not Yet Shipped","Not Yet Validated");
它工作正常。 但我需要添加新的条件语句。
这是我的带有数据的示例orders
表列。
total_grand | 总体状态 | televalidator_user_id |
---|---|---|
100 | 在途中 | 1个 |
200 | 还没寄出 | 1个 |
300 | 尚未验证 | NULL |
400 | 尚未验证 | 1个 |
500 | 在途中 | 1个 |
---------------------- | ------------------ | ------------------ |
我正在尝试总结total_grand
但如果 televalidator_user_id 是NULL
,则不应将其添加到底池中
因为row 3
有 null televalidator_user_id
output 必须是:1200
SELECT sum(total_grand) as total
FROM `orders`
WHERE overall_status in ("In-Transit", "Not Yet Shipped", "Not Yet Validated")
AND televalidator_user_id is not null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.