gpt4 book ai didi

mysql - 为具有相同 where 条件的同一个表的多个查询编写单个查询

转载 作者:行者123 更新时间:2023-11-29 14:41:45 24 4
gpt4 key购买 nike

select column1,column2,column3 from table1 where column5=0 and column6=0
select column1,column2,column3 from table1 where column5!=0 and column6!=0

这是两条从同一个表1读取数据的sql语句。有没有办法编写返回相同数据的单个查询?

我想要单个查询中 (column5 = 0 AND column6 = 0) 和 (column5 != 0 AND column6 != 0) 的单独结果。

as example:
select column1 as c1,column2 as c2,column3 as c3 from table1 where column5=0 and column6=0
union
select column1 as c1_,column2 as c2_,column3 as c3_ from table1 where column5!=0 and column6!=0

最佳答案

SELECT column1, column2, column3 
FROM table1
WHERE (column5 = 0 AND column6 = 0) OR (column5 != 0 AND column6 != 0)

关于mysql - 为具有相同 where 条件的同一个表的多个查询编写单个查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7857954/

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