mysql两列组合查询_mysql–在两列中组合两个select语句?如果您的每个查询只返回1⾏,您可以使⽤:
SELECT
(select Start_Date
from table1 where Start_Date not in (
select End_Date
from table1)
) AS StartDate,
(select End_Date from table1
where End_Date not in (
select Start_Date
from table1)
)
AS EndDate
如果您的查询返回超过1⾏,则必须选择其他解决⽅案:
你可以使⽤UNION:
(您将在另⼀列中将两个查询与“NULL”错位)
(select Start_Date, Null AS EndDate
from table1 where Start_Date not in (
select End_Date
from table1)
)
UNIONselect语句查询日期
(select Null As StartDate, End_Date
from table1
where End_Date not in (
select Start_Date
from table1)
)
你可以使⽤JOIN
如果你有⼀个字段⽤作“Join On”你可以使⽤这个字段,如果没有你可以添加⼀个字段来加⼊(但你需要检查返回的数据以避免错误)
你还要检查什么样的连接可能对你有好处(内 – 左 – rigth)
在⽰例中,我添加了⼀个字段来加⼊并使⽤内部联接:
SELECT Start_Date, End_Date
FROM
(select 1 as InnerId, Start_Date
from table1 where Start_Date not in ( select End_Date
from table1)
) As Tab1
INNER JOIN
(select 1 as InnerId, End_Date from table1 where End_Date not in (
select Start_Date
from table1)
) AS Tab2
USING(InnerId)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。