I wanted to use the view code written by my colleagues as a module, but then I realized it was like this.
Create view zc_ypz
Select zcgs, dwdm, zysx, hj, 1 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 1 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 2 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 1 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 3 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 1 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 4 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 1 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 5 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 1 and zysx <> 10 and zysx <> 7 and (mlbh not like '000000' and mlbh not like '000000' and mlbh
Not like '000000' and mlbh not like '000000' and mlbh not like '000000' and mlbh not like '000000') and
Mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 1 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 2 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 2 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 2 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 3 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 2 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 4 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 2 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 5 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk
Where zcgs = 2 and zysx <> 10 and zysx <> 7 and (mlbh not like '000000' and mlbh not like '000000' and mlbh
Not like '000000' and mlbh not like '000000' and mlbh not like '000000' and mlbh not like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 1 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk
Where zcgs = 3 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 2 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk
Where zcgs = 3 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 3 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk
Where zcgs = 3 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 4 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk
Where zcgs = 3 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 5 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk
Where zcgs = 3 and zysx <> 10 and zysx <> 7 and (mlbh not like '000000' and mlbh not like '000000' and mlbh
Not like '000000' and mlbh not like '000000' and mlbh not like '000000' and mlbh not like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 1 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk
Where zcgs = 4 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 2 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk
Where zcgs = 4 and zysx <> 10 and zysx <> 7 and (mlbh like '000000' or mlbh like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 3 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk
Where zcgs = 4 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 4 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk
Where zcgs = 4 and zysx <> 10 and zysx <> 7 and mlbh like '000000' and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 5 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk
Where zcgs = 4 and zysx <> 10 and zysx <> 7 and (mlbh not like '000000' and mlbh not like '000000' and mlbh
Not like '000000' and mlbh not like '000000' and mlbh not like '000000' and mlbh not like '000000') and mlbh not like '000000' group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 0 as kpml, sum (yzje) as aa, 0 as bb, 0 as cc, 0 as dd from zc_skpk where
Zcgs = 1 and zysx = 10 group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 0 as kpml, 0 as aa, sum (yzje) as bb, 0 as cc, 0 as dd from zc_skpk where
Zcgs = 2 and zysx = 10 group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 0 as kpml, 0 as aa, 0 as bb, sum (yzje) as cc, 0 as dd from zc_skpk where
Zcgs = 3 and zysx = 10 group by dwdm, zysx, hj, zcgs
Union
Select zcgs, dwdm, zysx, hj, 0 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (yzje) as dd from zc_skpk where
Zcgs = 4 and zysx = 10 group by dwdm, zysx, hj, zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 1 as kpml, sum (a. ZYLX_JE) as aa, 0 as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 1 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 2 as kpml, sum (a. ZYLX_JE) as aa, 0 as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 1 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 3 as kpml, sum (a. ZYLX_JE) as aa, 0 as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 1 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 4 as kpml, sum (a. ZYLX_JE) as aa, 0 as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 1 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 5 as kpml, sum (a. ZYLX_JE) as aa, 0 as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 1 and a. zylxbh <> 10 and (B. mlbh not like '000000' and B. mlbh not like '000000' and B. mlbh not
Like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200 ')
And mlbh not like '000000' group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 1 as kpml, 0 as aa, sum (a. ZYLX_JE) as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 2 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 2 as kpml, 0 as aa, sum (a. ZYLX_JE) as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 2 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 3 as kpml, 0 as aa, sum (a. ZYLX_JE) as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 2 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 4 as kpml, 0 as aa, sum (a. ZYLX_JE) as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 2 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 5 as kpml, 0 as aa, sum (a. ZYLX_JE) as bb, 0
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 2 and a. zylxbh <> 10 and (B. mlbh not like '000000' and B. mlbh not like '000000' and B. mlbh not
Like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200 ')
And mlbh not like '000000' group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 1 as kpml, 0 as aa, 0 as bb, sum (a. ZYLX_JE)
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 3 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 2 as kpml, 0 as aa, 0 as bb, sum (a. ZYLX_JE)
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 3 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 3 as kpml, 0 as aa, 0 as bb, sum (a. ZYLX_JE)
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 3 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 4 as kpml, 0 as aa, 0 as bb, sum (a. ZYLX_JE)
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 3 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 5 as kpml, 0 as aa, 0 as bb, sum (a. ZYLX_JE)
Cc, 0 as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and
B. zcgs = 3 and a. zylxbh <> 10 and (B. mlbh not like '000000' and B. mlbh not like '000000' and B. mlbh not
Like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200 ')
And mlbh not like '000000' group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 1 as kpml, 0 as aa,
0 as bb, 0 as cc, sum (a. ZYLX_JE) as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and
A. dwbh = B. dwdm and B. zysx = 7 and B. zcgs = 4 and a. zylxbh <> 10 and (B. mlbh like '200' or B. mlbh like
'200') and mlbh not like '200' group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 2 as kpml, 0 as aa, 0 as bb, 0 as cc, sum
(A. ZYLX_JE) as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7
And B. zcgs = 4 and. zylxbh <> 10 and (B. mlbh like '000000' or B. mlbh like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 3 as kpml, 0 as aa, 0 as bb, 0 as cc, sum
(A. ZYLX_JE) as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7
And B. zcgs = 4 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 4 as kpml, 0 as aa, 0 as bb, 0 as cc, sum
(A. ZYLX_JE) as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7
And B. zcgs = 4 and. zylxbh <> 10 and B. mlbh like '000000' and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm, a. zylxbh as zysx, B. hj, 5 as kpml, 0 as aa, 0 as bb, 0 as cc, sum
(A. ZYLX_JE) as dd from zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7
And B. zcgs = 4 and. zylxbh <> 10 and (B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '200' and B. mlbh not like '000000') and mlbh not like '000000' group by B. dwdm,. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm,. zylxbh as zysx, B. hj, 0 as kpml, sum (. ZYLX_JE) as aa, 0 as bb, 0 as cc, 0 as dd
From zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and B. zcgs = 1 and
A. zylxbh = 10 group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm,. zylxbh as zysx, B. hj, 0 as kpml, 0 as aa, sum (. ZYLX_JE) as bb, 0 as cc, 0 as dd
From zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and B. zcgs = 2 and
A. zylxbh = 10 group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm,. zylxbh as zysx, B. hj, 0 as kpml, 0 as aa, 0 as bb, sum (. ZYLX_JE) as cc, 0 as dd
From zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and B. zcgs = 3 and
A. zylxbh = 10 group by B. dwdm, a. zylxbh, B. hj, B. zcgs
Union
Select B. zcgs, B. dwdm,. zylxbh as zysx, B. hj, 0 as kpml, 0 as aa, 0 as bb, 0 as cc, sum (. ZYLX_JE) as dd
From zc_kpzylx a, zc_skpk B where a. kpbh = B. kpbh and a. dwbh = B. dwdm and B. zysx = 7 and B. zcgs = 4 and
A. zylxbh = 10 group by B. dwdm, a. zylxbh, B. hj, B. zcgs;