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
8 个解决方案
#1
可以优化,我写个SQL给你。
#2
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
#3
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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
试试这个SQL
为了优化:内层子查询没有使用m.appno = n.deriveno or m.appno = n.appno,而是采用union all
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