17,381
社区成员
发帖
与我相关
我的任务
分享
select n.deriveno,
n.appno,
to_char(m.appdt, 'yyyy/mm/dd') appdt,
m.passenger_qty,
m.ride_starttime,
m.ride_backtime,
m.appemplname,
e.deptid,
g.groupname,
g.groupscope,
m.udate
from app_main m,
app_nomapping n,
app_chargedept cd,
employee e,
bd_groupandaim g,
app_passenger p,
app_schedule sc
where m.appno = n.deriveno --这句
and m.appno = cd.appno
and m.appemplid = e.emplid
and m.aim_id = g.aim_id
and m.appno = p.appno
and m.appno = sc.appno
select n.deriveno,
n.appno,
to_char(m.appdt, 'yyyy/mm/dd') appdt,
m.passenger_qty,
m.ride_starttime,
m.ride_backtime,
m.appemplname,
e.deptid,
g.groupname,
g.groupscope,
m.udate
from app_main m,
app_nomapping n,
app_chargedept cd,
employee e,
bd_groupandaim g,
app_passenger p,
app_schedule sc
where m.appno = n.appno --这句
and m.appno = cd.appno
and m.appemplid = e.emplid
and m.aim_id = g.aim_id
and m.appno = p.appno
and m.appno = sc.appno
[/quote]
多出来的数据,是不是重复数据?
如果是的话,1. 要么把unionn all改成union ,2,要么在最外层的select后面加上distinct去重。[/quote]
不是,链接条件不一样导致的。我已经改成四个union并在一起了。写了300多行

select x.deriveno,
x.appno,
x.appdt,
x.passenger_qty,
x.ride_starttime,
x.ride_backtime,
x.appemplname,
e.deptid,
g.groupname,
g.groupscope,
x.udate
from(select n.deriveno,n.appno,m.passenger_qty,m.ride_starttime,
m.ride_backtime,m.appemplname,m.udate,aim_id,
m.appno as appno_m,m.appemplid,to_char(m.appdt, 'yyyy/mm/dd') appdt,
from app_main m,app_nomapping n
where m.appno = n.deriveno
union all
select n.deriveno,n.appno,m.passenger_qty,m.ride_starttime,
m.ride_backtime,m.appemplname,m.udate,aim_id,
m.appno as appno_m,m.appemplid,to_char(m.appdt, 'yyyy/mm/dd') appdt,
from app_main m,app_nomapping n
where m.appno = n.appno
)x,
app_chargedept cd,
employee e,
bd_groupandaim g,
app_passenger p,
app_schedule sc
where x.appno_m = cd.appno
and x.appemplid = e.emplid
and x.aim_id = g.aim_id
and x.appno_m = p.appno
and x.appno_m = sc.appno
