首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

Oracle 联合主键查询数据有关问题

2012-08-11 
Oracle 联合主键查询数据问题serviceaction 主键(orderno,actionno)其它表主键就是一个。select sp.orderno

Oracle 联合主键查询数据问题
serviceaction 主键(orderno,actionno)其它表主键就是一个。

select sp.orderno,sp.deptno,sp.zb_ordertime,       sp.consumer,sp.computertypeno,sp.servicetype,       sp.computerid,sp.product_code,sp.system,       op.orderprogress,sa.updatetime,sa.actionno,sa.missreason,       r.reasonfrom servicerepair sp,serviceaction sa,orderprogress op,reason rwhere sp.orderno = sa.orderno       and sp.orderprogressno = op.orderprogressno      and sp.orderprogressno in (-1,0,1,2,3,4)      and sa.missreason = r.reasonno      and sp.deptno = 'GZ'      and (sa.orderno,sa.actionno) in (           select s.orderno,max(s.actionno)            from (select sp.orderno,sa.actionno                 from servicerepair sp,serviceaction sa                 where sp.orderno = sa.orderno                  and sp.orderprogressno in (-1,0,1,2,3,4)                 and sp.deptno = 'GZ') s           group by s.orderno           );

纠结我1个多小时才写出来,因为serviceaction表里的同一个ordeno会有多个actionno与其对应。。。(使用group by解决)

热点排行