一个不简单查询!谢谢帮忙
原表内容如下:
A:
id name jd date1 date2
-------------------------------------------------------
001 螺丝 1 2007-04-01 2007-04-10
001 螺丝 2 2007-04-10 2007-04-18
002 钢板 1 2007-05-04 2007-05-21
002 钢板 2 2007-05-21 2007-05-30
要查询出的数据结构如下:
B:
id name jd1 1date1 1date2 jd2 2date1 2date2
-----------------------------------
001 螺丝 1 2007-04-01 2007-04-10 2 2007-04-10 2007-04-18
002 钢板 1 2007-05-04 2007-05-21 2 2007-05-21 2007-05-30
不知道大家看懂了没有!
请问怎么样查询查下表内容!
------解决方案----------------------方法基本是这样,语法有什么不对自己调试一下,快把分给我。。。。。。
select t1.id,t1.name,
t2.jd jd1 t2.date1 1date1,t2.date2 1date2,
t3.jd jd2 t2.date1 2date1,t3.date2 2date2,
from (select distinct id,name from a) t1,
a t2,
a t3
where t1.id=t2.id(+)
and t1.id=t2.id(+)
------解决方案--------------------select t_jd1.id,
t_jd1.name,
t_jd1.jd jd1,
t_jd1.date1 "1date1 ",
t_jd1.date2 "1date2 ",
t_jd2.jd jd2,
t_jd2.date1 "2date1 ",
t_jd2.date2 "2date2 "
from (select * from a where jd = 1) t_jd1,
(select * from a where jd = 2) t_jd2
where t_jd1.id = t_jd2.id(+)
--如果一个ID对应的各JD必定有值的话