我有以下查询。我做了联合以获得所需的输出,但我没有得到它。
create table foo (dateFact date, id int);
create table bar (dateFact date, id int);
insert into foo(dateFact, id) values('2013-03-01', 88), ('2013-03-02', 89),('2013-03-03', 90);
insert into bar(dateFact, id) values('2013-03-01', 88), ('2013-03-02', 89),('2013-03-03', 90);
select * from foo;
select * from bar;
(select dateFact, id as idA, 0 from foo order by dateFact) union (select dateFact, 0, id as idB from bar order by dateFact);
上面的查询给了我以下结果:
dateFact idA 0
2013-03-01 88 0
2013-03-02 89 0
2013-03-03 90 0
2013-03-01 0 88
2013-03-02 0 89
2013-03-03 0 90
但我想要:
dateFact idA idB
2013-03-01 88 88
2013-03-02 89 89
2013-03-03 90 90
感谢您的帮助!