Home > database >  How to deal with SQL execution too long, can shorten
How to deal with SQL execution too long, can shorten

Time:09-28

(
SELECT
B.i temcode,
B.d irectionidx,
C.p rintname,
A.c losedate,
A.s erialno,
Anderson temtype,
A. ranchcode,
A.c entercode,
A.y earmonth,
A.a ccbooktype,
A.a ccbookcode,
A.c losedate,
A.a ccountcode,
A.c hecktype,
A.c heckno,
A.c urrency,
Anderson temcode,
A. d. irectionidx,
B.r emark,
B.d ebitsource,
The biggest reditsource,
B.d ebitdest,
The biggest reditdest,
A. alancesource,
A. alancedest,
A.o peratecode,
A.o peratebranch,
A.o peratedate,
A.a pprovecode,
A.a pprovebranch,
A.a pprovedate,
A.c heckflag,
A.c heckyearmonth,
A.c hecknum,
A. d. ailytype,
Dr. Oucherno,
A.r eceflag,
A. d. etailidx,
A.f lag
The FROM
AccDailyRec AS a,
Accsubvoucherhis AS b,
(
(
SELECT
Printname,
Itemcode,
Directionidx,
Centercode
The FROM
Accitemvalidate
)
UNION ALL
(
SELECT
Itemname AS printname,
Itemcode,
'00' AS directionidx,
Centercode
The FROM
Accitemdefine
)
C)
WHERE
A.c entercode=biggest entercode
AND a.y earmonth=b.y earmonth
AND Dr. Oucherno=b.v oucherno
AND c.i temcode=b.i temcode
AND c.d irectionidx=b.d irectionidx
AND Arthur c. entercode=biggest entercode
AND b.i temcode & lt;> '1001'
AND the EXISTS (
SELECT
1
The FROM
Accmainvoucherhis er
WHERE
Er. Centercode=a.c entercode
AND er, yearmonth=a.y earmonth
AND er, voucherno=Dr. Oucherno
AND er. Voucherflag='4'
)
AND a.A ccBookType='02'
AND a.C enterCode='1000000000'
AND a.A ccBookCode='11'
AND a. ranchCode='1000000000'
AND Anderson, temType='0'
AND a.A ccountCode='z'
AND 1=1
AND a.C loseDate & gt;
='2017-03-01'AND a.C loseDate & lt;
='2017-03-31'The ORDER BY
Voucherdate,
Voucherno
)
UNION ALL
(
SELECT
B.i temcode,
B.d irectionidx,
C.p rintname,
A.c losedate,
A.s erialno,
Anderson temtype,
A. ranchcode,
A.c entercode,
A.y earmonth,
A.a ccbooktype,
A.a ccbookcode,
A.c losedate,
A.a ccountcode,
A.c hecktype,
A.c heckno,
A.c urrency,
Anderson temcode,
A. d. irectionidx,
B.r emark,
B.d ebitsource,
The biggest reditsource,
B.d ebitdest,
The biggest reditdest,
A. alancesource,
A. alancedest,
A.o peratecode,
A.o peratebranch,
A.o peratedate,
A.a pprovecode,
A.a pprovebranch,
A.a pprovedate,
A.c heckflag,
A.c heckyearmonth,
A.c hecknum,
A. d. ailytype,
Dr. Oucherno,
A.r eceflag,
A. d. etailidx,
A.f lag
The FROM
AccDailyRec AS a,
Accsubvoucher AS b,
(
(
SELECT
Printname,
Itemcode,
Directionidx,
Centercode
The FROM
Accitemvalidate
)
UNION ALL
(
SELECT
Itemname AS printname,
Itemcode,
'00' AS directionidx,
Centercode
The FROM
Accitemdefine
)
C)
WHERE
A.c entercode=biggest entercode
AND a.y earmonth=b.y earmonth
AND Dr. Oucherno=b.v oucherno
AND c.i temcode=b.i temcode
AND c.d irectionidx=b.d irectionidx
AND Arthur c. entercode=biggest entercode
AND b.i temcode & lt;> '1001'
AND the EXISTS (
SELECT
1
The FROM
Accmainvoucher er
WHERE
Er. Centercode=a.c entercode
AND er, yearmonth=a.y earmonth
AND er, voucherno=Dr. Oucherno
AND er. Voucherflag & lt;> '4'
)
AND a.A ccBookType='02'
AND a.C enterCode='1000000000'
AND a.A ccBookCode='11'
AND a. ranchCode='1000000000'
AND Anderson, temType='0'
AND a.A ccountCode='z'
AND 1=1
AND a.C loseDate & gt;
='2017-03-01'AND a.C loseDate & lt;
='2017-03-31'GROUP BY
B.v oucherno,
B.i temcode
The ORDER BY
Voucherdate,
Voucherno
)

CodePudding user response:

Pray for a great god help to look at, this piece of SQL to perform several times, date range, the greater the number of executions

CodePudding user response:

Refactor the code, the writing must be slow

CodePudding user response:

Can be * instead

CodePudding user response:

This kind of don't want to see at all==this line, perfect,,,,

CodePudding user response:

Can be used with tab_name as (select... ) at the back of the can directly use the select * from tab_name instead of

CodePudding user response:

Please create the view a try,

CodePudding user response:

The temporary table,
With tab_name as (select... ),
Process
You choose!
  • Related