好几天了,还没解决,如何得出如下结果(0分)

  • 主题发起人 主题发起人 maill01
  • 开始时间 开始时间
M

maill01

Unregistered / Unconfirmed
GUEST, unregistred user!
a:<br>select create_date1 from invoice group by create_date1<br><br>create_date<br>2008-04-27 <br>2008-05-15 <br>2008-05-16 <br><br>b:<br>select create_date2 from LoadingInvoice group by create_date2<br><br>create_date<br>2008-04-29 <br>2008-05-09 <br>2008-05-16<br><br><br>如何得出如下结果:<br>create_date1 &nbsp; &nbsp; &nbsp;create_date2<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008-04-27<br>2008-04-29 <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2008-05-09<br>2008-05-15 <br>2008-05-16 &nbsp; &nbsp; &nbsp; &nbsp;2008-05-16
 
把两个表的数据都放到一个临时表temp_table里去,然后排序,<br>如果你要得出create_date1表的结果呢,用一个update语句把temp_table表里和create_date2一样的记录设成null就行了<br><br>create_date2也一样
 
我觉得是不是可以变通的获取一下??<br>select create_date1,'create_date1' from invoice group by create_date1 <br>union <br>select create_date2,'create_date2' from LoadingInvoice group by create_date2<br>order by create_date1<br><br>只是随便说说,不行不要打我啊。
 
select create_date1 from invoice order by create_date1<br>union <br>select create_date2 from LoadingInvoice order by create_date1<br>&nbsp;where &nbsp;(create_date1=create_date2) or ((create_date1 is null) and (create_date2 is not null)) or ((create_date1 is not null) and (create_date2 is null))
 
仔细想了下 上面估计有问题<br>还是不要想一句SQL就处理好<br>第一步:新建个临时表<br>第二步:插入invoice表 create_date1,null<br>第三步:插入LoadingInvoice表 null,create_date2(当然要判断下是不是等于create_date1,等于则更新,否则就插入)
 
select * from<br>(select create_date1 from invoice group by create_date1) a<br>cross join<br>(select create_date2 from LoadingInvoice group by create_date2) b<br>on a.create_date1=b.create_date2<br><br>应该可以满足吧
 
select f.create_date1,f.create_date2<br>from<br>((select create_date1 as ad from a<br>union<br>select create_date2 as ad from b)c<br>left join a as d on d.create_date1=c.ad<br>left join b as e on e.create_date2=c.ad<br>)f
 
后退
顶部