帮我把“SELECT ppo.supplier_id, ppo.supplier_name, count(distinct ppo.id) FROM pm_purchase_order ppo inner join pm_purchase_order_detail ppod on ppo.id = ppod.purchase_order_id -- and ppod.confirm_status = '1' and ppod.del_flag = '0' WHERE ppo.del_flag = '0' GROUP BY ppo.supplier_id, ppo.supplier_name”和“SELECT ppo.supplier_id, ppo.supplier_name, count(distinct ppo.id) FROM pm_purchase_order ppo inner join pm_purchase_order_detail ppod on ppo.id = ppod.purchase_order_id and ppod.confirm_status = '1' and ppod.del_flag = '0' WHERE ppo.del_flag = '0' GROUP BY ppo.supplier_id, ppo.supplier_name”合并成一个SQL语句
时间: 2024-03-12 16:45:14 浏览: 98
SQL_select.rar_sql 语法
可以使用`OR`运算符将两个`SELECT`语句合并成一个,同时在第二个`SELECT`语句中添加一个条件判断,当`ppod.confirm_status`不等于1时,不计入结果。合并后的 SQL 语句如下:
```
SELECT ppo.supplier_id, ppo.supplier_name, count(distinct ppo.id)
FROM pm_purchase_order ppo
inner join pm_purchase_order_detail ppod on ppo.id = ppod.purchase_order_id
WHERE ppo.del_flag = '0' AND (ppod.confirm_status = '1' OR ppod.confirm_status <> '1' AND ppod.del_flag = '0')
GROUP BY ppo.supplier_id, ppo.supplier_name
```
注意,这个合并的语句中,`ppod.del_flag = '0'`条件是包含在括号里面的,因为它只对第二个`SELECT`语句生效。如果要对两个`SELECT`语句都生效,需要将这个条件移动到`WHERE`语句的外面,并使用`AND`运算符连接两个条件。
阅读全文