SELECT
-- max 加这个只是为了让字段不在分组里写
max(id) id,
max(stockorg_name) stockorg_name,
max(vbillcode) vbillcode,
max(source_no) source_no,
-- newvbillcode 这个字段做分组条件
newvbillcode,
max(dbilldate) dbilldate,
max(billtypename) billtypename,
max(vtrantypecode) vtrantypecode,
max(stordoc_code) stordoc_code,
max(stordoc_name) stordoc_name,
max(crowno) crowno,
max(MATERIAL_code) MATERIAL_code,
max(MATERIAL_name) MATERIAL_name,
max(vbatchcode) vbatchcode,
to_char ( sum( nnum ) ) AS nnum,
to_char ( sum( nassistnum ) ) AS nassistnum
FROM
(
SELECT
to_char ( rownum ) AS id,
NCC10.org_stockorg.NAME AS stockorg_name,
NCC10.IC_FINPRODIN_H.vbillcode,
NCC10.IC_FINPRODIN_H.VDEF44 AS source_no,
CASE
WHEN instr( NCC10.IC_FINPRODIN_H.vbillcode, '-',- 1 ) > 0 THEN
substr( NCC10.IC_FINPRODIN_H.vbillcode, 1, instr( NCC10.IC_FINPRODIN_H.vbillcode, '-',- 1 ) - 1 ) ELSE NCC10.IC_FINPRODIN_H.vbillcode
END newvbillcode,
substr( NCC10.IC_FINPRODIN_H.dbilldate, 1, 10 ) AS dbilldate,
NCC10.bd_billtype.billtypename,
NCC10.IC_FINPRODIN_H.vtrantypecode,
NCC10.bd_stordoc.CODE AS stordoc_code,
NCC10.bd_stordoc.NAME AS stordoc_name,
NCC10.IC_FINPRODIN_B.crowno,
NCC10.BD_MATERIAL.CODE AS MATERIAL_code,
NCC10.BD_MATERIAL.NAME AS MATERIAL_name,
NCC10.IC_FINPRODIN_B.vbatchcode,
NCC10.IC_FINPRODIN_B.nnum,
NCC10.IC_FINPRODIN_B.nassistnum
FROM
NCC10.IC_FINPRODIN_H
LEFT JOIN NCC10.IC_FINPRODIN_B ON NCC10.IC_FINPRODIN_H.cgeneralhid = NCC10.IC_FINPRODIN_B.cgeneralhid
LEFT JOIN NCC10.BD_MATERIAL ON NCC10.IC_FINPRODIN_B.cmaterialoid = NCC10.BD_MATERIAL.pk_material
AND NCC10.BD_MATERIAL.DR = 0
LEFT JOIN NCC10.bd_measdoc ON NCC10.bd_measdoc.pk_measdoc = NCC10.IC_FINPRODIN_B.castunitid
AND NCC10.bd_measdoc.DR = 0
LEFT JOIN NCC10.org_stockorg ON NCC10.org_stockorg.pk_stockorg = NCC10.IC_FINPRODIN_H.pk_org
AND NCC10.org_stockorg.DR = 0
LEFT JOIN NCC10.bd_stordoc ON NCC10.bd_stordoc.pk_stordoc = NCC10.IC_FINPRODIN_H.cwarehouseid
AND NCC10.bd_stordoc.DR = 0
LEFT JOIN NCC10.bd_billtype ON NCC10.bd_billtype.pk_billtypecode = NCC10.IC_FINPRODIN_H.vtrantypecode
AND NCC10.bd_billtype.DR = 0
WHERE
NCC10.IC_FINPRODIN_H.DR = 0
AND NCC10.IC_FINPRODIN_B.DR = 0
AND NCC10.IC_FINPRODIN_H.dbilldate >= concat( to_char ( add_months ( last_day( sysdate ) + 1,- 2 ), 'yyyy-MM-dd' ), ' 00:00:00' )
AND NCC10.IC_FINPRODIN_H.dbilldate < concat( to_char ( add_months ( last_day( sysdate ) + 1,- 1 ), 'yyyy-MM-dd' ), ' 00:00:00' )
) b
GROUP BY
newvbillcode
标签:bd,聚合,stordoc,max,单字,FINPRODIN,oracle,IC,NCC10
From: https://www.cnblogs.com/fuqian/p/16650614.html