bd.bdbm as bdbm,
bd.bdh as bdh,
bd.apbm as apbm
cc.apcc as apcc,
MAX(to_char(cc.jyrq, 'yyyy年MM月dd日')) as cjrq,
MAX(wt.jyfs) as jyfs,
MAX(wt.jyfx) as jyfx,
MAX(wt.jyfxmc) as jyfxmc,
MAX(wt.jyfsmc) as jyfsmc,
MAX(wt.wtfmc) as wtfmc,
MAX(cc.wtfbm) as wtfbm,
MAX(ht.pzmc) as pzmc,
MAX(ht.pzbm) as pzbm,
MAX(wt.lsxzbm) as lsxzbm,
MAX(CASE ht.jylx
WHEN '0' THEN ht.cmmc
WHEN '1' THEN ht.sgmc
ELSE NULL
END) as sgmc,
MAX(cc.ccbm) as ccbm
insert into ty_dcjybzxx (id, bdh, htbh, tsbz, yy, bjr, bjrq)
values (#{id}, #{bdh}, #{htbh}, #{tsbz}, #{yy}, #{bjr}, #{bjrq})
update ty_dcjybzxx set bdh = #{bdh}, htbh = #{htbh}, tsbz = #{tsbz}, yy = #{yy}, bjr = #{bjr}, bjrq = #{bjrq}
where id = #{id}
SELECT
FROM
(select * from ty_jycc c where c.apcc IN
( SELECT ht.apcc FROM ty_jyht ht
where
(instr(decode(ht.jylx, 0, ht.cmmc, 1, ht.sgmc), #{sgmc}) > 0)
GROUP BY ht.apcc
)) cc
ty_jycc cc
left join ty_jycrkwt wt on cc.wtbm = wt.wtbm
left join ty_jyht ht on ht.apcc = cc.apcc
and ht.htbm!='' and ht.htbm is not null
and instr(cc.apcc, #{apcc}) > 0
and cc.cczt = #{cczt}
and cc.jyrq = to_date(#{cjrq}, 'yyyy-mm-dd')
and cc.jyfx = #{jyfx}
and cc.jyfs = #{jyfs}
and instr(cc.wtfmc, #{wtfmc}) > 0
and instr(wt.pzbm, #{pzbm}) > 0
and wt.lsxzbm = #{lsxzbm}
GROUP BY cc.apcc
ORDER BY MAX(cc.ccbm) DESC
select cc.apcc,
ht.htbh as htbh,
ht.cckmc as cckmc,
ht.nch as nch,
ht.pzmc as pzmc,
ht.pzbm as pzbm,
ht.nnf as nnf,
ht.lssl as cjsl,
ht.qpdj as qpdj,
ht.cjdj as cjdj,
CASE ht.jylx
WHEN '0' THEN ht.cmmc
WHEN '1' THEN ht.sgmc
ELSE NULL
END as cjdw,
ht.je as je,
to_char(wt.wcsj, 'yyyy年MM月dd日') as cjrq
from ty_jyht ht
left join ty_jycc cc on cc.apcc = ht.apcc
left join ty_jycrkwt wt on wt.wtbm = cc.wtbm
where cc.apcc = #{apcc}
order by ht.htbh asc
select cc.apcc,
ht.htbh as htbh,
CASE ht.jylx
WHEN '0' THEN ht.cmmc
WHEN '1' THEN ht.sgmc
ELSE NULL
END as cjdw,
ht.cjdj as cjdj,
ht.lssl as cjsl,
ht.je as je,
cc.sxfl as sxfl,
cc.jybzj as jybzj,
cc.lybzj as lybzj,
cc.sxf_Type as sxfType,
ht.sjjke as sjjke,
wt.jyfx as jyfx,
wt.jyfs as jyfs,
ht.jylx as jylx,
wt.wtfmc as wtfmc,
wt.lsxzbm as lsxzbm,
to_char(wt.wcsj, 'yyyy年MM月dd日') as cjrq
from ty_jyht ht
left join ty_jycc cc on cc.apcc = ht.apcc
left join ty_jycrkwt wt on wt.wtbm = cc.wtbm
where cc.apcc = #{apcc}
order by ht.htbh asc
SELECT to_char(tcc.jyrq, 'yyyy年MM月dd日') as cjrq,
tcc.apcc as apcc,
case tap.aplx
when 0 then '采购'
when 1 then '销售'
else ''
end as jyfx,
case tap.aplx
when 0 then '采购'
when 1 then '销售'
else ''
end as jyfxmc,
-- tap.pzmc
tap.scnd as ccnx,
max(tap.pzmc) as pzmc,
tap.jydj as dj,
max(wt.lscd) as cd,
wm_concat(tap.bdbm) as bdbm
FROM ty_jycrkap tap
JOIN
ty_jycc tcc ON tap.wtbm = tcc.wtbm
JOIN
ty_jyht tht ON tcc.apcc = tht.apcc AND tcc.ccbm = tht.ccbm
join
ty_jycrkwt wt on wt.wtbm = tap.wtbm
tht.htbm is not null and tht.htbm != ''
and tcc.jyrq >= to_date(#{cjrqks}, 'yyyy-mm-dd')
and tcc.jyrq <= to_date(#{cjrqjs}, 'yyyy-mm-dd')
GROUP BY tap.aplx,
tcc.jyrq,
tcc.apcc,
tap.scnd,
tap.jydj
order by tcc.jyrq desc,tcc.jyrq desc
SELECT to_char(tcc.jyrq, 'yyyy年MM月dd日') as cjrq,
tcc.apcc as apcc,
case tap.aplx
when 0 then '采购'
when 1 then '销售'
else ''
end as jyfx,
case tap.aplx
when 0 then '采购'
when 1 then '销售'
else ''
end as jyfxmc,
-- tap.pzmc
tap.scnd as ccnx,
max(tap.pzmc) as pzmc,
tap.jydj as dj,
max(wt.lscd) as cd,
wm_concat(tap.bdbm) as bdbm
FROM ty_jycrkap tap
JOIN
ty_jycc tcc ON tap.wtbm = tcc.wtbm
JOIN
ty_jyht tht ON tcc.apcc = tht.apcc AND tcc.ccbm = tht.ccbm
join
ty_jycrkwt wt on wt.wtbm = tap.wtbm
tht.htbm is not null and tht.htbm != ''
and tcc.jyrq >= to_date(#{cjrqks}, 'yyyy-mm-dd')
and tcc.jyrq <= to_date(#{cjrqjs}, 'yyyy-mm-dd')
GROUP BY tap.aplx,
tcc.jyrq,
tcc.apcc,
tap.scnd,
tap.jydj
order by tcc.jyrq desc,tcc.apcc desc
select cc.apcc as cc,
cc.ccbh as ccbh,
to_char(cc.jyrq,'yyyy-MM-dd') as jyrq,
cc.wtfmc as wtf,
wt.lsxzbm as jyjb,
CASE ap.aplx
WHEN '0' THEN '采购'
WHEN '1' THEN '销售'
ELSE NULL
END as jylxmc,
ap.aplx as jylx,
wt.jyfs as jyfs,
wt.jyfsmc as jyfsmc,
ap.pzmc as pzmc,
ap.pzbm as pzbm,
ap.bdh as bdh,
ht.htbh as hth,
ap.lssl as bdsl,
ht.lssl as htsl,
ht.qpdj as qpj,
ht.cjdj as cjj,
(select lysl from ty_refund_notice rn where rn.htbm = ht.htbm and rn.zt = '92000400') as lysl,
(select wysl from ty_refund_notice rn where rn.htbm = ht.htbm and rn.zt = '92000400') as wysl,
CASE ht.jylx
WHEN '0' THEN ht.cmmc
WHEN '1' THEN ht.sgmc
ELSE NULL
END as cjkh,
(select wm_concat(kh.khmc) from ty_jycc_khxx kh where kh.wtbh=cc.wtbm) as bmkh,
ap.dwmc as ccdw,
ap.ccdd as ch,
ht.je as htje,
cc.sxfl as khsxfl,
cc.lybzj as lybzj,
cc.jybzj as jybzj
from ty_jycrkap ap
left join ty_jycc cc on cc.wtbm = ap.wtbm
left join ty_jyht ht on ap.bdbm = ht.bdbm
left join ty_jycrkwt wt on wt.wtbm = ap.wtbm
and cc.jyrq >= to_date(#{jyrqStart}, 'yyyy-mm-dd')
and cc.jyrq <= to_date(#{jyrqEnd}, 'yyyy-mm-dd')
and to_date(to_date(cc.jyrq,'yyyy-MM-dd')+2,'yyyy-MM-dd') < to_date(sysdate,'yyyy-MM-dd') and ht.htbh is null
and ht.htbh is not null
and to_date(to_date(cc.jyrq,'yyyy-MM-dd')+2,'yyyy-MM-dd') >= to_date(sysdate,'yyyy-MM-dd') and ht.htbh is null
and ap.aplx = #{jylx}
and wt.lsxzbm = #{jyjb}
and wt.jyfs = #{jyfs}
and ht.htbh like '%'||#{hth}||'%'
and ap.pzbm = #{pzbm}
and cc.apcc like '%'||#{cc}||'%'
and cc.wtfmc like '%'||#{wtf}||'%'
order by cc.jyrq desc,cc.apcc desc
select cc.apcc as cc,
cc.ccbh as ccbh,
to_char(cc.jyrq,'yyyy-MM-dd') as jyrq,
cc.wtfmc as wtf,
wt.lsxzbm as jyjb,
CASE ap.aplx
WHEN '0' THEN '采购'
WHEN '1' THEN '销售'
ELSE NULL
END as jylxmc,
ap.aplx as jylx,
wt.jyfs as jyfs,
wt.jyfsmc as jyfsmc,
ap.pzmc as pzmc,
ap.pzbm as pzbm,
ap.bdh as bdh,
ht.htbh as hth,
ap.lssl as bdsl,
ht.lssl as htsl,
ht.qpdj as qpj,
ht.cjdj as cjj,
(select lysl from ty_refund_notice rn where rn.htbm = ht.htbm and rn.zt = '92000400') as lysl,
(select wysl from ty_refund_notice rn where rn.htbm = ht.htbm and rn.zt = '92000400') as wysl,
CASE ht.jylx
WHEN '0' THEN ht.cmmc
WHEN '1' THEN ht.sgmc
ELSE NULL
END as cjkh,
(select wm_concat(kh.khmc) from ty_jycc_khxx kh where kh.wtbh=cc.wtbm) as bmkh,
ap.dwmc as ccdw,
ap.ccdd as ch,
ht.je as htje,
cc.sxfl as khsxfl,
cc.lybzj as lybzj,
cc.jybzj as jybzj
from ty_jycrkap ap
left join ty_jycc cc on cc.wtbm = ap.wtbm
left join ty_jyht ht on ap.bdbm = ht.bdbm
left join ty_jycrkwt wt on wt.wtbm = ap.wtbm
and cc.jyrq >= to_date(#{jyrqStart}, 'yyyy-mm-dd')
and cc.jyrq <= to_date(#{jyrqEnd}, 'yyyy-mm-dd')
and to_date(to_date(cc.jyrq,'yyyy-MM-dd')+2,'yyyy-MM-dd') < to_date(sysdate,'yyyy-MM-dd') and ht.htbh is null
and ht.htbh is not null
and to_date(to_date(cc.jyrq,'yyyy-MM-dd')+2,'yyyy-MM-dd') >= to_date(sysdate,'yyyy-MM-dd') and ht.htbh is null
and ap.aplx = #{jylx}
and wt.lsxzbm = #{jyjb}
and wt.jyfs = #{jyfs}
and ht.htbh like '%'||#{hth}||'%'
and ap.pzbm = #{pzbm}
and cc.apcc like '%'||#{cc}||'%'
and cc.wtfmc like '%'||#{wtf}||'%'
order by cc.jyrq desc,cc.apcc desc
SELECT main.cc,
main.ccbh,
to_char(main.jyrq,'yyyy-MM-dd') as jyrq,
main.wtf,
main.jyjb,
main.jylx,
main.jylxmc,
main.jyfs,
main.jyfsmc,
main.pzmc,
main.pzbm,
SUM(CAST(main.bdsl AS decimal)) as bdsl,
SUM(CAST(main.htsl AS decimal)) as htsl,
SUM(rn.lysl) as lysl,
SUM(rn.wysl) as wysl,
SUM(CAST(main.htje AS decimal)) as htje,
SUM(rn.lysl * main.cjdj) as lyje,
SUM((main.sxfl / 100) * main.htje) as sxfje
FROM (SELECT cc.apcc as cc,
cc.ccbh as ccbh,
cc.jyrq as jyrq,
cc.wtfmc as wtf,
wt.lsxzbm as jyjb,
CASE ap.aplx
WHEN '0' THEN '采购'
WHEN '1' THEN '销售'
ELSE NULL
END as jylxmc,
ap.aplx as jylx,
wt.jyfs as jyfs,
wt.jyfsmc as jyfsmc,
ap.pzmc as pzmc,
ap.pzbm as pzbm,
ap.lssl as bdsl,
ht.lssl as htsl,
ht.je as htje,
ht.htbm as htbm,
ht.cjdj as cjdj,
cc.sxfl as sxfl
FROM ty_jycc cc
LEFT JOIN
ty_jycrkap ap ON cc.wtbm = ap.wtbm
LEFT JOIN
ty_jyht ht ON ap.bdbm = ht.bdbm
LEFT JOIN
ty_jycrkwt wt ON wt.wtbm = ap.wtbm
) as main
LEFT JOIN
ty_refund_notice rn ON rn.htbm = main.htbm AND rn.zt = '92000400'
and main.jyrq >= to_date(#{jyrqStart}, 'yyyy-mm-dd')
and main.jyrq <= to_date(#{jyrqEnd}, 'yyyy-mm-dd')
and main.jylx = #{jylx}
and main.jyjb = #{jyjb}
and main.jyfs = #{jyfs}
and main.pzbm = #{pzbm}
and main.cc like '%'||#{cc}||'%'
and main.wtf like '%'||#{wtf}||'%'
GROUP BY main.cc, main.ccbh,main.jylxmc,main.jylx, main.jyrq, main.wtf, main.jyjb, main.jylxmc, main.jyfs, main.jyfsmc,
main.pzmc, main.pzbm order by main.jyrq desc,main.cc desc
SELECT main.cc,
main.ccbh,
to_char(main.jyrq,'yyyy-MM-dd') as jyrq,
main.wtf,
main.jyjb,
main.jylx,
main.jylxmc,
main.jyfs,
main.jyfsmc,
main.pzmc,
main.pzbm,
SUM(CAST(main.bdsl AS decimal)) as bdsl,
SUM(CAST(main.htsl AS decimal)) as htsl,
SUM(rn.lysl) as lysl,
SUM(rn.wysl) as wysl,
SUM(CAST(main.htje AS decimal)) as htje,
SUM(rn.lysl * main.cjdj) as lyje,
SUM((main.sxfl / 100) * main.htje) as sxfje
FROM (SELECT cc.apcc as cc,
cc.ccbh as ccbh,
cc.jyrq as jyrq,
cc.wtfmc as wtf,
wt.lsxzbm as jyjb,
CASE ap.aplx
WHEN '0' THEN '采购'
WHEN '1' THEN '销售'
ELSE NULL
END as jylxmc,
ap.aplx as jylx,
wt.jyfs as jyfs,
wt.jyfsmc as jyfsmc,
ap.pzmc as pzmc,
ap.pzbm as pzbm,
ap.lssl as bdsl,
ht.lssl as htsl,
ht.je as htje,
ht.htbm as htbm,
ht.cjdj as cjdj,
cc.sxfl as sxfl
FROM ty_jycc cc
LEFT JOIN
ty_jycrkap ap ON cc.wtbm = ap.wtbm
LEFT JOIN
ty_jyht ht ON ap.bdbm = ht.bdbm
LEFT JOIN
ty_jycrkwt wt ON wt.wtbm = ap.wtbm
) as main
LEFT JOIN
ty_refund_notice rn ON rn.htbm = main.htbm AND rn.zt = '92000400'
and main.jyrq >= to_date(#{jyrqStart}, 'yyyy-mm-dd')
and main.jyrq <= to_date(#{jyrqEnd}, 'yyyy-mm-dd')
and main.jylx = #{jylx}
and main.jyjb = #{jyjb}
and main.jyfs = #{jyfs}
and main.pzbm = #{pzbm}
and main.cc like '%'||#{cc}||'%'
and main.wtf like '%'||#{wtf}||'%'
GROUP BY main.cc, main.ccbh,main.jylxmc,main.jylx, main.jyrq, main.wtf, main.jyjb, main.jylxmc, main.jyfs, main.jyfsmc,
main.pzmc, main.pzbm order by main.jyrq desc,main.cc desc
select * from ty_dcjybzxx;