Mysql 查询以匹配和连接给定日期的两行。嗨,我是新手,已经用谷歌搜索并搜索了几天的堆栈溢出,但我找不到答案。请帮助解决以下问题
我有一张桌子:人
Id Leader Name1 Name2 StartDate EndDate
123 1 Person1 2013-02-11 2013-02-17
123 0 Person2 2013-02-13 2013-02-13
123 0 Person3 2013-02-13 2013-02-13
我有一个问题1
(SELECT t1.Id, t1.Name1, t1.Name2
FROM `dbo`.`people` t1
WHERE t1.StartDate >= '2013-02-11'
AND t1.Leader = 1)
UNION
(SELECT t2.Id, t2.Name1, t1.Name2
FROM `dbo`.`people` t2
WHERE t2.StartDate >= '2013-02-11'
AND t2.Leader = 0)
这返回
Id Name1 Name2
123, Person1
我有一个查询2
(SELECT t1.Id, t1.Name1, t1.Name2
FROM `dbo`.`people` t1
WHERE t1.StartDate >= '2013-02-13'
AND t1.Leader = 1)
UNION
(SELECT t2.Id, t2.Name1, t1.Name2
FROM `dbo`.`people` t2
WHERE t2.StartDate >= '2013-02-13'
AND t2.Leader = 0)
这返回
Id Name1 Name2
123, Person1
123, Person2
123, Person3
我需要 2012-02-11 的结果来显示
Id Name1 Name2
123, Person1 null
并为 2012-02-13 显示
Id Name1 Name2
123, Person1 Person2
123, Person1 Person3