多表查询如何优化sql语句
语句一select logs.op_type,logs.op_date,logs.mer_id, m.name,logs.user_name,logs.phone,b.bus_name from (select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG1
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG2
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG3
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG4
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG5
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG6
union all
select rec_id ,op_date ,op_type,pay_type,mer_id ,user_name,phone from TBL_DBN_TXN_LOG7
)as logs,
(select mer.mer_no as mer_id1,mer.name,mer.bus_id as bus_id1 from TBL_DBN_MER_INFO as mer) as m,
(select bus.bus_name ,bus.bus_id as bus_id2 from TBL_DBN_BUS_INFO as bus where 1=1 ) as b
where m.mer_id1=logs.mer_id and m.bus_id1=b.bus_id2 and 1=1 order by logs.op_date
语句2
select a.mer_id,a.mer_name ,a.order_time,b.bus_name from(select bus.bus_name,bus.bus_id as bus_id1 from TBL_DBN_BUS_INFO as bus ) as b,
(select mer.mer_no as mer_id2 ,mer.bus_id as bus_id2 from TBL_DBN_MER_INFO as mer ) as m, TBL_DBN_MER_ORDER as a where not exists(select 1 from TBL_DBN_ORDER_REC c where c.order_id=a.order_id ) and m.mer_id2=a.mer_id and m.bus_id2=b.bus_id1 and 1=1 order by a.order_time
语句3
Select logs.order_time,mb.vendor_name,logs.mer_id,mb.name, logs.order_id,logs.cups_trace,
(cast(logs.order_amt as Double)/100)as order_amt1, logs.pay_type,logs.tran_type,logs.iss_id,
(select a.name from TBL_DBN_BANK as a where a.iss_id=logs.iss_id), logs.card_no,logs.card_type,logs.resp_code,
(select resp_desc_temp from tbl_dbn_resp_temp where logs.resp_code= resp_code fetch first 1 rows only), logs.phone,logs.user_name,logs.tran_time,logs.ver_id from
( select * from
(select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG1 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG2 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG3 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG4 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG5 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG6 union all select order_time, mer_id ,order_id ,cups_trace,order_amt,pay_type,tran_type,iss_id,card_no,card_type,resp_code,phone,user_name,tran_time,ver_id from TBL_DBN_TXN_LOG7 ) as mess where exists
(select 1 from TBL_DBN_ORDER_REC as r where r.order_id=mess.order_id and r.mer_id=mess.mer_id and r.order_time=mess.order_time ) )as logs ,
(select c.mer_no,c.name,c.vendor_id as vendor_id, (select b.vendor_name from TBL_DBN_DEV_INFO as b where c.vendor_id=b.vendor_id) from TBL_DBN_MER_INFO as c) as mb where mb.mer_no=logs.mer_id and 1=1
以上是我在做项目时写的查询语句,我知道很烂。;
在做查询时由于每个TBL_DBN_TXN_LOG表在100万条左右, 而且涉及到很多个表之间信息的相互访问,由于是web查询,所以一会就崩溃了,我真的不知道该怎么优化了,希望各位高手们给出点建议。
”创建索引“就不要说了
--------------------编程问答-------------------- 我去.....这也太长了吧
补充:Java , Java相关