--************************************************************************** --* 売上データの出力範囲を取得 --*  --************************************************************************** [lselectRecords] --売上データ select DTS_YEAR ,DTS_MONTH FROM T_SALE where DT_SALE >= '&2' and DT_SALE <= '&3' and (('&4' = '') or (CD_CUSTOMER >= TO_NUMBER('&4'))) and (('&5' = '') or (CD_CUSTOMER <= TO_NUMBER('&5'))) and (('&6' = '') or (CD_DERIVERY >= TO_NUMBER('&6'))) and (('&7' = '') or (CD_DERIVERY >= TO_NUMBER('&7'))) and (('&8' = '') or (CD_GREAD >= TO_NUMBER('&8'))) and FLG_DELETE = 0 group by DTS_YEAR, DTS_MONTH --入金データ union select DTS_YEAR ,DTS_MONTH from T_DEPOSIT where DT_DEPOSIT >= '&2' and DT_DEPOSIT <= '&3' and (('&4' = '') or (CD_CUSTOMER >= TO_NUMBER('&4'))) and (('&5' = '') or (CD_CUSTOMER <= TO_NUMBER('&5'))) and (('&6' = '') or (CD_DERIVERY >= TO_NUMBER('&6'))) and (('&7' = '') or (CD_DERIVERY >= TO_NUMBER('&7'))) and DIV_DELETE = 0 group by DTS_YEAR, DTS_MONTH order by DTS_YEAR, DTS_MONTH --************************************************************************** --* 得意先、納品先別の売上データを取得 --*  --************************************************************************** [lselectRecords21] SELECT MC.CD_CUSTOMER ,MD.CD_DERIVERY ,MC.NAME_CUSTOMER ,MD.NAME_DERIVERY ,round((CASE WHEN SUM(TS.WEIGHT_SALE01) = 0 THEN SUM(TS.MONEY_SALE01) ELSE SUM(TS.MONEY_SALE01) / SUM(TS.WEIGHT_SALE01) END) ::numeric, 1) UNIT_PRICE_SALE1 ,round((CASE WHEN SUM(TS.WEIGHT_SALE02) = 0 THEN SUM(TS.MONEY_SALE02) ELSE SUM(TS.MONEY_SALE02) / SUM(TS.WEIGHT_SALE02) END) ::numeric, 1) UNIT_PRICE_SALE2 ,round((CASE WHEN SUM(TS.WEIGHT_SALE03) = 0 THEN SUM(TS.MONEY_SALE03) ELSE SUM(TS.MONEY_SALE03) / SUM(TS.WEIGHT_SALE03) END) ::numeric, 1) UNIT_PRICE_SALE3 ,round((CASE WHEN SUM(TS.WEIGHT_SALE04) = 0 THEN SUM(TS.MONEY_SALE04) ELSE SUM(TS.MONEY_SALE04) / SUM(TS.WEIGHT_SALE04) END) ::numeric, 1) UNIT_PRICE_SALE4 ,round((CASE WHEN SUM(TS.WEIGHT_SALE05) = 0 THEN SUM(TS.MONEY_SALE05) ELSE SUM(TS.MONEY_SALE05) / SUM(TS.WEIGHT_SALE05) END) ::numeric, 1) UNIT_PRICE_SALE5 ,round((CASE WHEN SUM(TS.WEIGHT_SALE06) = 0 THEN SUM(TS.MONEY_SALE06) ELSE SUM(TS.MONEY_SALE06) / SUM(TS.WEIGHT_SALE06) END) ::numeric, 1) UNIT_PRICE_SALE6 ,round((CASE WHEN SUM(TS.WEIGHT_SALE07) = 0 THEN SUM(TS.MONEY_SALE07) ELSE SUM(TS.MONEY_SALE07) / SUM(TS.WEIGHT_SALE07) END) ::numeric, 1) UNIT_PRICE_SALE7 ,round((CASE WHEN SUM(TS.WEIGHT_SALE08) = 0 THEN SUM(TS.MONEY_SALE08) ELSE SUM(TS.MONEY_SALE08) / SUM(TS.WEIGHT_SALE08) END) ::numeric, 1) UNIT_PRICE_SALE8 ,round((CASE WHEN SUM(TS.WEIGHT_SALE09) = 0 THEN SUM(TS.MONEY_SALE09) ELSE SUM(TS.MONEY_SALE09) / SUM(TS.WEIGHT_SALE09) END) ::numeric, 1) UNIT_PRICE_SALE9 ,round((CASE WHEN SUM(TS.WEIGHT_SALE10) = 0 THEN SUM(TS.MONEY_SALE10) ELSE SUM(TS.MONEY_SALE10) / SUM(TS.WEIGHT_SALE10) END) ::numeric, 1) UNIT_PRICE_SALE10 ,round((CASE WHEN SUM(TS.WEIGHT_SALE11) = 0 THEN SUM(TS.MONEY_SALE11) ELSE SUM(TS.MONEY_SALE11) / SUM(TS.WEIGHT_SALE11) END) ::numeric, 1) UNIT_PRICE_SALE11 ,round((CASE WHEN SUM(TS.WEIGHT_SALE12) = 0 THEN SUM(TS.MONEY_SALE12) ELSE SUM(TS.MONEY_SALE12) / SUM(TS.WEIGHT_SALE12) END) ::numeric, 1) UNIT_PRICE_SALE12 ,round((CASE WHEN SUM(TS.WEIGHT_SALE13) = 0 THEN SUM(TS.MONEY_SALE13) ELSE SUM(TS.MONEY_SALE13) / SUM(TS.WEIGHT_SALE13) END) ::numeric, 1) UNIT_PRICE_SALE13 ,round((CASE WHEN SUM(TS.WEIGHT_SALE14) = 0 THEN SUM(TS.MONEY_SALE14) ELSE SUM(TS.MONEY_SALE14) / SUM(TS.WEIGHT_SALE14) END) ::numeric, 1) UNIT_PRICE_SALE14 ,round((CASE WHEN SUM(TS.WEIGHT_SALE15) = 0 THEN SUM(TS.MONEY_SALE15) ELSE SUM(TS.MONEY_SALE15) / SUM(TS.WEIGHT_SALE15) END) ::numeric, 1) UNIT_PRICE_SALE15 ,round((CASE WHEN SUM(TS.WEIGHT_SALE16) = 0 THEN SUM(TS.MONEY_SALE16) ELSE SUM(TS.MONEY_SALE16) / SUM(TS.WEIGHT_SALE16) END) ::numeric, 1) UNIT_PRICE_SALE16 ,round((CASE WHEN SUM(TS.WEIGHT_SALE17) = 0 THEN SUM(TS.MONEY_SALE17) ELSE SUM(TS.MONEY_SALE17) / SUM(TS.WEIGHT_SALE17) END) ::numeric, 1) UNIT_PRICE_SALE17 ,round((CASE WHEN SUM(TS.WEIGHT_SALE18) = 0 THEN SUM(TS.MONEY_SALE18) ELSE SUM(TS.MONEY_SALE18) / SUM(TS.WEIGHT_SALE18) END) ::numeric, 1) UNIT_PRICE_SALE18 ,round((CASE WHEN SUM(TS.WEIGHT_SALE19) = 0 THEN SUM(TS.MONEY_SALE19) ELSE SUM(TS.MONEY_SALE19) / SUM(TS.WEIGHT_SALE19) END) ::numeric, 1) UNIT_PRICE_SALE19 ,round((CASE WHEN SUM(TS.WEIGHT_SALE20) = 0 THEN SUM(TS.MONEY_SALE20) ELSE SUM(TS.MONEY_SALE20) / SUM(TS.WEIGHT_SALE20) END) ::numeric, 1) UNIT_PRICE_SALE20 ,round((CASE WHEN SUM(TS.WEIGHT_SALE21) = 0 THEN SUM(TS.MONEY_SALE21) ELSE SUM(TS.MONEY_SALE21) / SUM(TS.WEIGHT_SALE21) END) ::numeric, 1) UNIT_PRICE_SALE21 ,round((CASE WHEN SUM(TS.WEIGHT_SALE22) = 0 THEN SUM(TS.MONEY_SALE22) ELSE SUM(TS.MONEY_SALE22) / SUM(TS.WEIGHT_SALE22) END) ::numeric, 1) UNIT_PRICE_SALE22 ,round((CASE WHEN SUM(TS.WEIGHT_SALE23) = 0 THEN SUM(TS.MONEY_SALE23) ELSE SUM(TS.MONEY_SALE23) / SUM(TS.WEIGHT_SALE23) END) ::numeric, 1) UNIT_PRICE_SALE23 ,round((CASE WHEN SUM(TS.WEIGHT_SALE24) = 0 THEN SUM(TS.MONEY_SALE24) ELSE SUM(TS.MONEY_SALE24) / SUM(TS.WEIGHT_SALE24) END) ::numeric, 1) UNIT_PRICE_SALE24 ,round((CASE WHEN SUM(TS.WEIGHT_SALE25) = 0 THEN SUM(TS.MONEY_SALE25) ELSE SUM(TS.MONEY_SALE25) / SUM(TS.WEIGHT_SALE25) END) ::numeric, 1) UNIT_PRICE_SALE25 ,round((CASE WHEN SUM(TS.WEIGHT_SALE26) = 0 THEN SUM(TS.MONEY_SALE26) ELSE SUM(TS.MONEY_SALE26) / SUM(TS.WEIGHT_SALE26) END) ::numeric, 1) UNIT_PRICE_SALE26 ,round((CASE WHEN SUM(TS.WEIGHT_SALE27) = 0 THEN SUM(TS.MONEY_SALE27) ELSE SUM(TS.MONEY_SALE27) / SUM(TS.WEIGHT_SALE27) END) ::numeric, 1) UNIT_PRICE_SALE27 ,round((CASE WHEN SUM(TS.WEIGHT_SALE28) = 0 THEN SUM(TS.MONEY_SALE28) ELSE SUM(TS.MONEY_SALE28) / SUM(TS.WEIGHT_SALE28) END) ::numeric, 1) UNIT_PRICE_SALE28 ,round((CASE WHEN SUM(TS.WEIGHT_SALE29) = 0 THEN SUM(TS.MONEY_SALE29) ELSE SUM(TS.MONEY_SALE29) / SUM(TS.WEIGHT_SALE29) END) ::numeric, 1) UNIT_PRICE_SALE29 ,round((CASE WHEN SUM(TS.WEIGHT_SALE30) = 0 THEN SUM(TS.MONEY_SALE30) ELSE SUM(TS.MONEY_SALE30) / SUM(TS.WEIGHT_SALE30) END) ::numeric, 1) UNIT_PRICE_SALE30 ,round((CASE WHEN SUM(TS.WEIGHT_SALE31) = 0 THEN SUM(TS.MONEY_SALE31) ELSE SUM(TS.MONEY_SALE31) / SUM(TS.WEIGHT_SALE31) END) ::numeric, 1) UNIT_PRICE_SALE31 ,SUM(TS.WEIGHT_SALE01) WEIGHT_SALE1 ,SUM(TS.WEIGHT_SALE02) WEIGHT_SALE2 ,SUM(TS.WEIGHT_SALE03) WEIGHT_SALE3 ,SUM(TS.WEIGHT_SALE04) WEIGHT_SALE4 ,SUM(TS.WEIGHT_SALE05) WEIGHT_SALE5 ,SUM(TS.WEIGHT_SALE06) WEIGHT_SALE6 ,SUM(TS.WEIGHT_SALE07) WEIGHT_SALE7 ,SUM(TS.WEIGHT_SALE08) WEIGHT_SALE8 ,SUM(TS.WEIGHT_SALE09) WEIGHT_SALE9 ,SUM(TS.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS.WEIGHT_SALE31) WEIGHT_SALE31 ,SUM(TS.MONEY_SALE01) MONEY_SALE1 ,SUM(TS.MONEY_SALE02) MONEY_SALE2 ,SUM(TS.MONEY_SALE03) MONEY_SALE3 ,SUM(TS.MONEY_SALE04) MONEY_SALE4 ,SUM(TS.MONEY_SALE05) MONEY_SALE5 ,SUM(TS.MONEY_SALE06) MONEY_SALE6 ,SUM(TS.MONEY_SALE07) MONEY_SALE7 ,SUM(TS.MONEY_SALE08) MONEY_SALE8 ,SUM(TS.MONEY_SALE09) MONEY_SALE9 ,SUM(TS.MONEY_SALE10) MONEY_SALE10 ,SUM(TS.MONEY_SALE11) MONEY_SALE11 ,SUM(TS.MONEY_SALE12) MONEY_SALE12 ,SUM(TS.MONEY_SALE13) MONEY_SALE13 ,SUM(TS.MONEY_SALE14) MONEY_SALE14 ,SUM(TS.MONEY_SALE15) MONEY_SALE15 ,SUM(TS.MONEY_SALE16) MONEY_SALE16 ,SUM(TS.MONEY_SALE17) MONEY_SALE17 ,SUM(TS.MONEY_SALE18) MONEY_SALE18 ,SUM(TS.MONEY_SALE19) MONEY_SALE19 ,SUM(TS.MONEY_SALE20) MONEY_SALE20 ,SUM(TS.MONEY_SALE21) MONEY_SALE21 ,SUM(TS.MONEY_SALE22) MONEY_SALE22 ,SUM(TS.MONEY_SALE23) MONEY_SALE23 ,SUM(TS.MONEY_SALE24) MONEY_SALE24 ,SUM(TS.MONEY_SALE25) MONEY_SALE25 ,SUM(TS.MONEY_SALE26) MONEY_SALE26 ,SUM(TS.MONEY_SALE27) MONEY_SALE27 ,SUM(TS.MONEY_SALE28) MONEY_SALE28 ,SUM(TS.MONEY_SALE29) MONEY_SALE29 ,SUM(TS.MONEY_SALE30) MONEY_SALE30 ,SUM(TS.MONEY_SALE31) MONEY_SALE31 ,SUM(TS.TAX01) TAX1 ,SUM(TS.TAX02) TAX2 ,SUM(TS.TAX03) TAX3 ,SUM(TS.TAX04) TAX4 ,SUM(TS.TAX05) TAX5 ,SUM(TS.TAX06) TAX6 ,SUM(TS.TAX07) TAX7 ,SUM(TS.TAX08) TAX8 ,SUM(TS.TAX09) TAX9 ,SUM(TS.TAX10) TAX10 ,SUM(TS.TAX11) TAX11 ,SUM(TS.TAX12) TAX12 ,SUM(TS.TAX13) TAX13 ,SUM(TS.TAX14) TAX14 ,SUM(TS.TAX15) TAX15 ,SUM(TS.TAX16) TAX16 ,SUM(TS.TAX17) TAX17 ,SUM(TS.TAX18) TAX18 ,SUM(TS.TAX19) TAX19 ,SUM(TS.TAX20) TAX20 ,SUM(TS.TAX21) TAX21 ,SUM(TS.TAX22) TAX22 ,SUM(TS.TAX23) TAX23 ,SUM(TS.TAX24) TAX24 ,SUM(TS.TAX25) TAX25 ,SUM(TS.TAX26) TAX26 ,SUM(TS.TAX27) TAX27 ,SUM(TS.TAX28) TAX28 ,SUM(TS.TAX29) TAX29 ,SUM(TS.TAX30) TAX30 ,SUM(TS.TAX31) TAX31 ,SUM(TS_PRE.WEIGHT_SALE) WEIGHT_SALE_PRE ,SUM(TS_PRE.MONEY_SALE) MONEY_SALE_PRE ,SUM(TS_PRE.TAX) TAX_PRE ,SUM(TS_PRE.MONEY_ADJUST) MONEY_ADJUST_PRE ,SUM(TS_PRE.MONEY_FREIGHT) MONEY_FREIGHT_PRE FROM ( SELECT TS02.CD_CUSTOMER CD_CUSTOMER ,TS02.CD_DERIVERY CD_DERIVERY ,SUM(TS02.WEIGHT_SALE01) WEIGHT_SALE01 ,SUM(TS02.WEIGHT_SALE02) WEIGHT_SALE02 ,SUM(TS02.WEIGHT_SALE03) WEIGHT_SALE03 ,SUM(TS02.WEIGHT_SALE04) WEIGHT_SALE04 ,SUM(TS02.WEIGHT_SALE05) WEIGHT_SALE05 ,SUM(TS02.WEIGHT_SALE06) WEIGHT_SALE06 ,SUM(TS02.WEIGHT_SALE07) WEIGHT_SALE07 ,SUM(TS02.WEIGHT_SALE08) WEIGHT_SALE08 ,SUM(TS02.WEIGHT_SALE09) WEIGHT_SALE09 ,SUM(TS02.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS02.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS02.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS02.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS02.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS02.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS02.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS02.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS02.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS02.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS02.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS02.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS02.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS02.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS02.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS02.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS02.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS02.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS02.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS02.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS02.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS02.WEIGHT_SALE31) WEIGHT_SALE31 ,SUM(TS02.MONEY_SALE01) MONEY_SALE01 ,SUM(TS02.MONEY_SALE02) MONEY_SALE02 ,SUM(TS02.MONEY_SALE03) MONEY_SALE03 ,SUM(TS02.MONEY_SALE04) MONEY_SALE04 ,SUM(TS02.MONEY_SALE05) MONEY_SALE05 ,SUM(TS02.MONEY_SALE06) MONEY_SALE06 ,SUM(TS02.MONEY_SALE07) MONEY_SALE07 ,SUM(TS02.MONEY_SALE08) MONEY_SALE08 ,SUM(TS02.MONEY_SALE09) MONEY_SALE09 ,SUM(TS02.MONEY_SALE10) MONEY_SALE10 ,SUM(TS02.MONEY_SALE11) MONEY_SALE11 ,SUM(TS02.MONEY_SALE12) MONEY_SALE12 ,SUM(TS02.MONEY_SALE13) MONEY_SALE13 ,SUM(TS02.MONEY_SALE14) MONEY_SALE14 ,SUM(TS02.MONEY_SALE15) MONEY_SALE15 ,SUM(TS02.MONEY_SALE16) MONEY_SALE16 ,SUM(TS02.MONEY_SALE17) MONEY_SALE17 ,SUM(TS02.MONEY_SALE18) MONEY_SALE18 ,SUM(TS02.MONEY_SALE19) MONEY_SALE19 ,SUM(TS02.MONEY_SALE20) MONEY_SALE20 ,SUM(TS02.MONEY_SALE21) MONEY_SALE21 ,SUM(TS02.MONEY_SALE22) MONEY_SALE22 ,SUM(TS02.MONEY_SALE23) MONEY_SALE23 ,SUM(TS02.MONEY_SALE24) MONEY_SALE24 ,SUM(TS02.MONEY_SALE25) MONEY_SALE25 ,SUM(TS02.MONEY_SALE26) MONEY_SALE26 ,SUM(TS02.MONEY_SALE27) MONEY_SALE27 ,SUM(TS02.MONEY_SALE28) MONEY_SALE28 ,SUM(TS02.MONEY_SALE29) MONEY_SALE29 ,SUM(TS02.MONEY_SALE30) MONEY_SALE30 ,SUM(TS02.MONEY_SALE31) MONEY_SALE31 ,SUM(TS02.TAX01) TAX01 ,SUM(TS02.TAX02) TAX02 ,SUM(TS02.TAX03) TAX03 ,SUM(TS02.TAX04) TAX04 ,SUM(TS02.TAX05) TAX05 ,SUM(TS02.TAX06) TAX06 ,SUM(TS02.TAX07) TAX07 ,SUM(TS02.TAX08) TAX08 ,SUM(TS02.TAX09) TAX09 ,SUM(TS02.TAX10) TAX10 ,SUM(TS02.TAX11) TAX11 ,SUM(TS02.TAX12) TAX12 ,SUM(TS02.TAX13) TAX13 ,SUM(TS02.TAX14) TAX14 ,SUM(TS02.TAX15) TAX15 ,SUM(TS02.TAX16) TAX16 ,SUM(TS02.TAX17) TAX17 ,SUM(TS02.TAX18) TAX18 ,SUM(TS02.TAX19) TAX19 ,SUM(TS02.TAX20) TAX20 ,SUM(TS02.TAX21) TAX21 ,SUM(TS02.TAX22) TAX22 ,SUM(TS02.TAX23) TAX23 ,SUM(TS02.TAX24) TAX24 ,SUM(TS02.TAX25) TAX25 ,SUM(TS02.TAX26) TAX26 ,SUM(TS02.TAX27) TAX27 ,SUM(TS02.TAX28) TAX28 ,SUM(TS02.TAX29) TAX29 ,SUM(TS02.TAX30) TAX30 ,SUM(TS02.TAX31) TAX31 ,SUM(TS02.MONEY_ADJUST01) MONEY_ADJUST01 ,SUM(TS02.MONEY_ADJUST02) MONEY_ADJUST02 ,SUM(TS02.MONEY_ADJUST03) MONEY_ADJUST03 ,SUM(TS02.MONEY_ADJUST04) MONEY_ADJUST04 ,SUM(TS02.MONEY_ADJUST05) MONEY_ADJUST05 ,SUM(TS02.MONEY_ADJUST06) MONEY_ADJUST06 ,SUM(TS02.MONEY_ADJUST07) MONEY_ADJUST07 ,SUM(TS02.MONEY_ADJUST08) MONEY_ADJUST08 ,SUM(TS02.MONEY_ADJUST09) MONEY_ADJUST09 ,SUM(TS02.MONEY_ADJUST10) MONEY_ADJUST10 ,SUM(TS02.MONEY_ADJUST11) MONEY_ADJUST11 ,SUM(TS02.MONEY_ADJUST12) MONEY_ADJUST12 ,SUM(TS02.MONEY_ADJUST13) MONEY_ADJUST13 ,SUM(TS02.MONEY_ADJUST14) MONEY_ADJUST14 ,SUM(TS02.MONEY_ADJUST15) MONEY_ADJUST15 ,SUM(TS02.MONEY_ADJUST16) MONEY_ADJUST16 ,SUM(TS02.MONEY_ADJUST17) MONEY_ADJUST17 ,SUM(TS02.MONEY_ADJUST18) MONEY_ADJUST18 ,SUM(TS02.MONEY_ADJUST19) MONEY_ADJUST19 ,SUM(TS02.MONEY_ADJUST20) MONEY_ADJUST20 ,SUM(TS02.MONEY_ADJUST21) MONEY_ADJUST21 ,SUM(TS02.MONEY_ADJUST22) MONEY_ADJUST22 ,SUM(TS02.MONEY_ADJUST23) MONEY_ADJUST23 ,SUM(TS02.MONEY_ADJUST24) MONEY_ADJUST24 ,SUM(TS02.MONEY_ADJUST25) MONEY_ADJUST25 ,SUM(TS02.MONEY_ADJUST26) MONEY_ADJUST26 ,SUM(TS02.MONEY_ADJUST27) MONEY_ADJUST27 ,SUM(TS02.MONEY_ADJUST28) MONEY_ADJUST28 ,SUM(TS02.MONEY_ADJUST29) MONEY_ADJUST29 ,SUM(TS02.MONEY_ADJUST30) MONEY_ADJUST30 ,SUM(TS02.MONEY_ADJUST31) MONEY_ADJUST31 ,SUM(TS02.MONEY_FREIGHT01) MONEY_FREIGHT01 ,SUM(TS02.MONEY_FREIGHT02) MONEY_FREIGHT02 ,SUM(TS02.MONEY_FREIGHT03) MONEY_FREIGHT03 ,SUM(TS02.MONEY_FREIGHT04) MONEY_FREIGHT04 ,SUM(TS02.MONEY_FREIGHT05) MONEY_FREIGHT05 ,SUM(TS02.MONEY_FREIGHT06) MONEY_FREIGHT06 ,SUM(TS02.MONEY_FREIGHT07) MONEY_FREIGHT07 ,SUM(TS02.MONEY_FREIGHT08) MONEY_FREIGHT08 ,SUM(TS02.MONEY_FREIGHT09) MONEY_FREIGHT09 ,SUM(TS02.MONEY_FREIGHT10) MONEY_FREIGHT10 ,SUM(TS02.MONEY_FREIGHT11) MONEY_FREIGHT11 ,SUM(TS02.MONEY_FREIGHT12) MONEY_FREIGHT12 ,SUM(TS02.MONEY_FREIGHT13) MONEY_FREIGHT13 ,SUM(TS02.MONEY_FREIGHT14) MONEY_FREIGHT14 ,SUM(TS02.MONEY_FREIGHT15) MONEY_FREIGHT15 ,SUM(TS02.MONEY_FREIGHT16) MONEY_FREIGHT16 ,SUM(TS02.MONEY_FREIGHT17) MONEY_FREIGHT17 ,SUM(TS02.MONEY_FREIGHT18) MONEY_FREIGHT18 ,SUM(TS02.MONEY_FREIGHT19) MONEY_FREIGHT19 ,SUM(TS02.MONEY_FREIGHT20) MONEY_FREIGHT20 ,SUM(TS02.MONEY_FREIGHT21) MONEY_FREIGHT21 ,SUM(TS02.MONEY_FREIGHT22) MONEY_FREIGHT22 ,SUM(TS02.MONEY_FREIGHT23) MONEY_FREIGHT23 ,SUM(TS02.MONEY_FREIGHT24) MONEY_FREIGHT24 ,SUM(TS02.MONEY_FREIGHT25) MONEY_FREIGHT25 ,SUM(TS02.MONEY_FREIGHT26) MONEY_FREIGHT26 ,SUM(TS02.MONEY_FREIGHT27) MONEY_FREIGHT27 ,SUM(TS02.MONEY_FREIGHT28) MONEY_FREIGHT28 ,SUM(TS02.MONEY_FREIGHT29) MONEY_FREIGHT29 ,SUM(TS02.MONEY_FREIGHT30) MONEY_FREIGHT30 ,SUM(TS02.MONEY_FREIGHT31) MONEY_FREIGHT31 FROM ( SELECT TS01.CD_CUSTOMER ,TS01.CD_DERIVERY ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE31 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE31 ,CASE WHEN TS01.DTS_DAY = 01 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX01 ,CASE WHEN TS01.DTS_DAY = 02 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX02 ,CASE WHEN TS01.DTS_DAY = 03 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX03 ,CASE WHEN TS01.DTS_DAY = 04 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX04 ,CASE WHEN TS01.DTS_DAY = 05 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX05 ,CASE WHEN TS01.DTS_DAY = 06 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX06 ,CASE WHEN TS01.DTS_DAY = 07 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX07 ,CASE WHEN TS01.DTS_DAY = 08 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX08 ,CASE WHEN TS01.DTS_DAY = 09 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX09 ,CASE WHEN TS01.DTS_DAY = 10 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX10 ,CASE WHEN TS01.DTS_DAY = 11 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX11 ,CASE WHEN TS01.DTS_DAY = 12 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX12 ,CASE WHEN TS01.DTS_DAY = 13 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX13 ,CASE WHEN TS01.DTS_DAY = 14 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX14 ,CASE WHEN TS01.DTS_DAY = 15 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX15 ,CASE WHEN TS01.DTS_DAY = 16 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX16 ,CASE WHEN TS01.DTS_DAY = 17 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX17 ,CASE WHEN TS01.DTS_DAY = 18 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX18 ,CASE WHEN TS01.DTS_DAY = 19 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX19 ,CASE WHEN TS01.DTS_DAY = 20 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX20 ,CASE WHEN TS01.DTS_DAY = 21 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX21 ,CASE WHEN TS01.DTS_DAY = 22 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX22 ,CASE WHEN TS01.DTS_DAY = 23 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX23 ,CASE WHEN TS01.DTS_DAY = 24 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX24 ,CASE WHEN TS01.DTS_DAY = 25 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX25 ,CASE WHEN TS01.DTS_DAY = 26 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX26 ,CASE WHEN TS01.DTS_DAY = 27 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX27 ,CASE WHEN TS01.DTS_DAY = 28 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX28 ,CASE WHEN TS01.DTS_DAY = 29 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX29 ,CASE WHEN TS01.DTS_DAY = 30 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX30 ,CASE WHEN TS01.DTS_DAY = 31 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX31 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST31 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT31 FROM T_SALE TS01 WHERE (('&1' = '') OR (TS01.DTS_YEAR = ('&1' ::text) ::numeric)) AND (('&2' = '') OR (TS01.DTS_MONTH = ('&2' ::text) ::numeric)) and TS01.FLG_DELETE = 0 and (('&6' = '') OR (TS01.CD_GREAD = ('&6' ::text) ::numeric)) ) TS02 GROUP BY TS02.CD_CUSTOMER, TS02.CD_DERIVERY ) ts, m_customer mc, m_derivery md LEFT OUTER JOIN ( SELECT TS03.CD_CUSTOMER ,TS03.CD_DERIVERY ,SUM(TS03.WEIGHT_SALE) WEIGHT_SALE ,SUM(TS03.MONEY_SALE) MONEY_SALE ,SUM(TS03.TAX) TAX ,SUM(TS03.MONEY_ADJUST) MONEY_ADJUST ,SUM(TS03.MONEY_FREIGHT) MONEY_FREIGHT FROM T_SALE TS03 WHERE (('&5' = '') OR (TS03.DTS_YEAR = ('&5' ::text) ::numeric)) AND (('&3' = '') OR (TS03.DTS_MONTH = ('&3' ::text) ::numeric)) AND DTS_DAY >= 21 AND DTS_DAY <= 31 and TS03.FLG_DELETE = 0 and (('&6' = '') OR (TS03.CD_GREAD = ('&6' ::text) ::numeric)) GROUP BY TS03.CD_CUSTOMER, TS03.CD_DERIVERY ) ts_pre ON (MD.CD_CUSTOMER = TS_PRE.CD_CUSTOMER AND MD.CD_DERIVERY = TS_PRE.CD_DERIVERY) WHERE MC.CD_CUSTOMER = MD.CD_CUSTOMER AND MD.CD_CUSTOMER = TS.CD_CUSTOMER AND MD.CD_DERIVERY = TS.CD_DERIVERY AND MC.DT_START = ( SELECT MAX(MC01.DT_START) FROM M_CUSTOMER MC01 WHERE MC01.CD_CUSTOMER = MC.CD_CUSTOMER) AND MD.DT_START = ( SELECT MAX(MD01.DT_START) FROM M_DERIVERY MD01 WHERE MD01.CD_DERIVERY = MD.CD_DERIVERY) AND (('&4' = '') OR (MC.CD_CUSTOMER = ('&4' ::text) ::numeric)) GROUP BY MC.CD_CUSTOMER, MD.CD_DERIVERY, MC.NAME_CUSTOMER, MD.NAME_DERIVERY ORDER BY MC.CD_CUSTOMER, MD.CD_DERIVERY, MC.NAME_CUSTOMER, MD.NAME_DERIVERY --************************************************************************** --* 得意先別の売上データを取得 --*  --************************************************************************** [lselectRecords22] SELECT MC.CD_CUSTOMER ,MC.NAME_CUSTOMER -- 単価 ,round((CASE WHEN SUM(TS.WEIGHT_SALE01) = 0 THEN SUM(TS.MONEY_SALE01) ELSE SUM(TS.MONEY_SALE01) / SUM(TS.WEIGHT_SALE01) END) ::numeric, 1) UNIT_PRICE_SALE1 ,round((CASE WHEN SUM(TS.WEIGHT_SALE02) = 0 THEN SUM(TS.MONEY_SALE02) ELSE SUM(TS.MONEY_SALE02) / SUM(TS.WEIGHT_SALE02) END) ::numeric, 1) UNIT_PRICE_SALE2 ,round((CASE WHEN SUM(TS.WEIGHT_SALE03) = 0 THEN SUM(TS.MONEY_SALE03) ELSE SUM(TS.MONEY_SALE03) / SUM(TS.WEIGHT_SALE03) END) ::numeric, 1) UNIT_PRICE_SALE3 ,round((CASE WHEN SUM(TS.WEIGHT_SALE04) = 0 THEN SUM(TS.MONEY_SALE04) ELSE SUM(TS.MONEY_SALE04) / SUM(TS.WEIGHT_SALE04) END) ::numeric, 1) UNIT_PRICE_SALE4 ,round((CASE WHEN SUM(TS.WEIGHT_SALE05) = 0 THEN SUM(TS.MONEY_SALE05) ELSE SUM(TS.MONEY_SALE05) / SUM(TS.WEIGHT_SALE05) END) ::numeric, 1) UNIT_PRICE_SALE5 ,round((CASE WHEN SUM(TS.WEIGHT_SALE06) = 0 THEN SUM(TS.MONEY_SALE06) ELSE SUM(TS.MONEY_SALE06) / SUM(TS.WEIGHT_SALE06) END) ::numeric, 1) UNIT_PRICE_SALE6 ,round((CASE WHEN SUM(TS.WEIGHT_SALE07) = 0 THEN SUM(TS.MONEY_SALE07) ELSE SUM(TS.MONEY_SALE07) / SUM(TS.WEIGHT_SALE07) END) ::numeric, 1) UNIT_PRICE_SALE7 ,round((CASE WHEN SUM(TS.WEIGHT_SALE08) = 0 THEN SUM(TS.MONEY_SALE08) ELSE SUM(TS.MONEY_SALE08) / SUM(TS.WEIGHT_SALE08) END) ::numeric, 1) UNIT_PRICE_SALE8 ,round((CASE WHEN SUM(TS.WEIGHT_SALE09) = 0 THEN SUM(TS.MONEY_SALE09) ELSE SUM(TS.MONEY_SALE09) / SUM(TS.WEIGHT_SALE09) END) ::numeric, 1) UNIT_PRICE_SALE9 ,round((CASE WHEN SUM(TS.WEIGHT_SALE10) = 0 THEN SUM(TS.MONEY_SALE10) ELSE SUM(TS.MONEY_SALE10) / SUM(TS.WEIGHT_SALE10) END) ::numeric, 1) UNIT_PRICE_SALE10 ,round((CASE WHEN SUM(TS.WEIGHT_SALE11) = 0 THEN SUM(TS.MONEY_SALE11) ELSE SUM(TS.MONEY_SALE11) / SUM(TS.WEIGHT_SALE11) END) ::numeric, 1) UNIT_PRICE_SALE11 ,round((CASE WHEN SUM(TS.WEIGHT_SALE12) = 0 THEN SUM(TS.MONEY_SALE12) ELSE SUM(TS.MONEY_SALE12) / SUM(TS.WEIGHT_SALE12) END) ::numeric, 1) UNIT_PRICE_SALE12 ,round((CASE WHEN SUM(TS.WEIGHT_SALE13) = 0 THEN SUM(TS.MONEY_SALE13) ELSE SUM(TS.MONEY_SALE13) / SUM(TS.WEIGHT_SALE13) END) ::numeric, 1) UNIT_PRICE_SALE13 ,round((CASE WHEN SUM(TS.WEIGHT_SALE14) = 0 THEN SUM(TS.MONEY_SALE14) ELSE SUM(TS.MONEY_SALE14) / SUM(TS.WEIGHT_SALE14) END) ::numeric, 1) UNIT_PRICE_SALE14 ,round((CASE WHEN SUM(TS.WEIGHT_SALE15) = 0 THEN SUM(TS.MONEY_SALE15) ELSE SUM(TS.MONEY_SALE15) / SUM(TS.WEIGHT_SALE15) END) ::numeric, 1) UNIT_PRICE_SALE15 ,round((CASE WHEN SUM(TS.WEIGHT_SALE16) = 0 THEN SUM(TS.MONEY_SALE16) ELSE SUM(TS.MONEY_SALE16) / SUM(TS.WEIGHT_SALE16) END) ::numeric, 1) UNIT_PRICE_SALE16 ,round((CASE WHEN SUM(TS.WEIGHT_SALE17) = 0 THEN SUM(TS.MONEY_SALE17) ELSE SUM(TS.MONEY_SALE17) / SUM(TS.WEIGHT_SALE17) END) ::numeric, 1) UNIT_PRICE_SALE17 ,round((CASE WHEN SUM(TS.WEIGHT_SALE18) = 0 THEN SUM(TS.MONEY_SALE18) ELSE SUM(TS.MONEY_SALE18) / SUM(TS.WEIGHT_SALE18) END) ::numeric, 1) UNIT_PRICE_SALE18 ,round((CASE WHEN SUM(TS.WEIGHT_SALE19) = 0 THEN SUM(TS.MONEY_SALE19) ELSE SUM(TS.MONEY_SALE19) / SUM(TS.WEIGHT_SALE19) END) ::numeric, 1) UNIT_PRICE_SALE19 ,round((CASE WHEN SUM(TS.WEIGHT_SALE20) = 0 THEN SUM(TS.MONEY_SALE20) ELSE SUM(TS.MONEY_SALE20) / SUM(TS.WEIGHT_SALE20) END) ::numeric, 1) UNIT_PRICE_SALE20 ,round((CASE WHEN SUM(TS.WEIGHT_SALE21) = 0 THEN SUM(TS.MONEY_SALE21) ELSE SUM(TS.MONEY_SALE21) / SUM(TS.WEIGHT_SALE21) END) ::numeric, 1) UNIT_PRICE_SALE21 ,round((CASE WHEN SUM(TS.WEIGHT_SALE22) = 0 THEN SUM(TS.MONEY_SALE22) ELSE SUM(TS.MONEY_SALE22) / SUM(TS.WEIGHT_SALE22) END) ::numeric, 1) UNIT_PRICE_SALE22 ,round((CASE WHEN SUM(TS.WEIGHT_SALE23) = 0 THEN SUM(TS.MONEY_SALE23) ELSE SUM(TS.MONEY_SALE23) / SUM(TS.WEIGHT_SALE23) END) ::numeric, 1) UNIT_PRICE_SALE23 ,round((CASE WHEN SUM(TS.WEIGHT_SALE24) = 0 THEN SUM(TS.MONEY_SALE24) ELSE SUM(TS.MONEY_SALE24) / SUM(TS.WEIGHT_SALE24) END) ::numeric, 1) UNIT_PRICE_SALE24 ,round((CASE WHEN SUM(TS.WEIGHT_SALE25) = 0 THEN SUM(TS.MONEY_SALE25) ELSE SUM(TS.MONEY_SALE25) / SUM(TS.WEIGHT_SALE25) END) ::numeric, 1) UNIT_PRICE_SALE25 ,round((CASE WHEN SUM(TS.WEIGHT_SALE26) = 0 THEN SUM(TS.MONEY_SALE26) ELSE SUM(TS.MONEY_SALE26) / SUM(TS.WEIGHT_SALE26) END) ::numeric, 1) UNIT_PRICE_SALE26 ,round((CASE WHEN SUM(TS.WEIGHT_SALE27) = 0 THEN SUM(TS.MONEY_SALE27) ELSE SUM(TS.MONEY_SALE27) / SUM(TS.WEIGHT_SALE27) END) ::numeric, 1) UNIT_PRICE_SALE27 ,round((CASE WHEN SUM(TS.WEIGHT_SALE28) = 0 THEN SUM(TS.MONEY_SALE28) ELSE SUM(TS.MONEY_SALE28) / SUM(TS.WEIGHT_SALE28) END) ::numeric, 1) UNIT_PRICE_SALE28 ,round((CASE WHEN SUM(TS.WEIGHT_SALE29) = 0 THEN SUM(TS.MONEY_SALE29) ELSE SUM(TS.MONEY_SALE29) / SUM(TS.WEIGHT_SALE29) END) ::numeric, 1) UNIT_PRICE_SALE29 ,round((CASE WHEN SUM(TS.WEIGHT_SALE30) = 0 THEN SUM(TS.MONEY_SALE30) ELSE SUM(TS.MONEY_SALE30) / SUM(TS.WEIGHT_SALE30) END) ::numeric, 1) UNIT_PRICE_SALE30 ,round((CASE WHEN SUM(TS.WEIGHT_SALE31) = 0 THEN SUM(TS.MONEY_SALE31) ELSE SUM(TS.MONEY_SALE31) / SUM(TS.WEIGHT_SALE31) END) ::numeric, 1) UNIT_PRICE_SALE31 -- 日別の数量 ,SUM(TS.WEIGHT_SALE01) WEIGHT_SALE1 ,SUM(TS.WEIGHT_SALE02) WEIGHT_SALE2 ,SUM(TS.WEIGHT_SALE03) WEIGHT_SALE3 ,SUM(TS.WEIGHT_SALE04) WEIGHT_SALE4 ,SUM(TS.WEIGHT_SALE05) WEIGHT_SALE5 ,SUM(TS.WEIGHT_SALE06) WEIGHT_SALE6 ,SUM(TS.WEIGHT_SALE07) WEIGHT_SALE7 ,SUM(TS.WEIGHT_SALE08) WEIGHT_SALE8 ,SUM(TS.WEIGHT_SALE09) WEIGHT_SALE9 ,SUM(TS.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS.MONEY_SALE01) MONEY_SALE1 ,SUM(TS.MONEY_SALE02) MONEY_SALE2 ,SUM(TS.MONEY_SALE03) MONEY_SALE3 ,SUM(TS.MONEY_SALE04) MONEY_SALE4 ,SUM(TS.MONEY_SALE05) MONEY_SALE5 ,SUM(TS.MONEY_SALE06) MONEY_SALE6 ,SUM(TS.MONEY_SALE07) MONEY_SALE7 ,SUM(TS.MONEY_SALE08) MONEY_SALE8 ,SUM(TS.MONEY_SALE09) MONEY_SALE9 ,SUM(TS.MONEY_SALE10) MONEY_SALE10 ,SUM(TS.MONEY_SALE11) MONEY_SALE11 ,SUM(TS.MONEY_SALE12) MONEY_SALE12 ,SUM(TS.MONEY_SALE13) MONEY_SALE13 ,SUM(TS.MONEY_SALE14) MONEY_SALE14 ,SUM(TS.MONEY_SALE15) MONEY_SALE15 ,SUM(TS.MONEY_SALE16) MONEY_SALE16 ,SUM(TS.MONEY_SALE17) MONEY_SALE17 ,SUM(TS.MONEY_SALE18) MONEY_SALE18 ,SUM(TS.MONEY_SALE19) MONEY_SALE19 ,SUM(TS.MONEY_SALE20) MONEY_SALE20 ,SUM(TS.MONEY_SALE21) MONEY_SALE21 ,SUM(TS.MONEY_SALE22) MONEY_SALE22 ,SUM(TS.MONEY_SALE23) MONEY_SALE23 ,SUM(TS.MONEY_SALE24) MONEY_SALE24 ,SUM(TS.MONEY_SALE25) MONEY_SALE25 ,SUM(TS.MONEY_SALE26) MONEY_SALE26 ,SUM(TS.MONEY_SALE27) MONEY_SALE27 ,SUM(TS.MONEY_SALE28) MONEY_SALE28 ,SUM(TS.MONEY_SALE29) MONEY_SALE29 ,SUM(TS.MONEY_SALE30) MONEY_SALE30 ,SUM(TS.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS.TAX01) TAX1 ,SUM(TS.TAX02) TAX2 ,SUM(TS.TAX03) TAX3 ,SUM(TS.TAX04) TAX4 ,SUM(TS.TAX05) TAX5 ,SUM(TS.TAX06) TAX6 ,SUM(TS.TAX07) TAX7 ,SUM(TS.TAX08) TAX8 ,SUM(TS.TAX09) TAX9 ,SUM(TS.TAX10) TAX10 ,SUM(TS.TAX11) TAX11 ,SUM(TS.TAX12) TAX12 ,SUM(TS.TAX13) TAX13 ,SUM(TS.TAX14) TAX14 ,SUM(TS.TAX15) TAX15 ,SUM(TS.TAX16) TAX16 ,SUM(TS.TAX17) TAX17 ,SUM(TS.TAX18) TAX18 ,SUM(TS.TAX19) TAX19 ,SUM(TS.TAX20) TAX20 ,SUM(TS.TAX21) TAX21 ,SUM(TS.TAX22) TAX22 ,SUM(TS.TAX23) TAX23 ,SUM(TS.TAX24) TAX24 ,SUM(TS.TAX25) TAX25 ,SUM(TS.TAX26) TAX26 ,SUM(TS.TAX27) TAX27 ,SUM(TS.TAX28) TAX28 ,SUM(TS.TAX29) TAX29 ,SUM(TS.TAX30) TAX30 ,SUM(TS.TAX31) TAX31 -- 日別の入金額 ,SUM(TD.MONEY_DEPOSIT01) MONEY_DEPOSIT1 ,SUM(TD.MONEY_DEPOSIT02) MONEY_DEPOSIT2 ,SUM(TD.MONEY_DEPOSIT03) MONEY_DEPOSIT3 ,SUM(TD.MONEY_DEPOSIT04) MONEY_DEPOSIT4 ,SUM(TD.MONEY_DEPOSIT05) MONEY_DEPOSIT5 ,SUM(TD.MONEY_DEPOSIT06) MONEY_DEPOSIT6 ,SUM(TD.MONEY_DEPOSIT07) MONEY_DEPOSIT7 ,SUM(TD.MONEY_DEPOSIT08) MONEY_DEPOSIT8 ,SUM(TD.MONEY_DEPOSIT09) MONEY_DEPOSIT9 ,SUM(TD.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 調整額は売上調整額と伝票の運賃と入金調整額とする。 -- 日別の伝票調整額 + 日別の運賃 - 日別の入金調整額 ,SUM(TS.MONEY_ADJUST01 + TS.MONEY_FREIGHT01 - TD.MONEY_DEPOSIT_ADJ01) ADJUST1 ,SUM(TS.MONEY_ADJUST02 + TS.MONEY_FREIGHT02 - TD.MONEY_DEPOSIT_ADJ02) ADJUST2 ,SUM(TS.MONEY_ADJUST03 + TS.MONEY_FREIGHT03 - TD.MONEY_DEPOSIT_ADJ03) ADJUST3 ,SUM(TS.MONEY_ADJUST04 + TS.MONEY_FREIGHT04 - TD.MONEY_DEPOSIT_ADJ04) ADJUST4 ,SUM(TS.MONEY_ADJUST05 + TS.MONEY_FREIGHT05 - TD.MONEY_DEPOSIT_ADJ05) ADJUST5 ,SUM(TS.MONEY_ADJUST06 + TS.MONEY_FREIGHT06 - TD.MONEY_DEPOSIT_ADJ06) ADJUST6 ,SUM(TS.MONEY_ADJUST07 + TS.MONEY_FREIGHT07 - TD.MONEY_DEPOSIT_ADJ07) ADJUST7 ,SUM(TS.MONEY_ADJUST08 + TS.MONEY_FREIGHT08 - TD.MONEY_DEPOSIT_ADJ08) ADJUST8 ,SUM(TS.MONEY_ADJUST09 + TS.MONEY_FREIGHT09 - TD.MONEY_DEPOSIT_ADJ09) ADJUST9 ,SUM(TS.MONEY_ADJUST10 + TS.MONEY_FREIGHT10 - TD.MONEY_DEPOSIT_ADJ10) ADJUST10 ,SUM(TS.MONEY_ADJUST11 + TS.MONEY_FREIGHT11 - TD.MONEY_DEPOSIT_ADJ11) ADJUST11 ,SUM(TS.MONEY_ADJUST12 + TS.MONEY_FREIGHT12 - TD.MONEY_DEPOSIT_ADJ12) ADJUST12 ,SUM(TS.MONEY_ADJUST13 + TS.MONEY_FREIGHT13 - TD.MONEY_DEPOSIT_ADJ13) ADJUST13 ,SUM(TS.MONEY_ADJUST14 + TS.MONEY_FREIGHT14 - TD.MONEY_DEPOSIT_ADJ14) ADJUST14 ,SUM(TS.MONEY_ADJUST15 + TS.MONEY_FREIGHT15 - TD.MONEY_DEPOSIT_ADJ15) ADJUST15 ,SUM(TS.MONEY_ADJUST16 + TS.MONEY_FREIGHT16 - TD.MONEY_DEPOSIT_ADJ16) ADJUST16 ,SUM(TS.MONEY_ADJUST17 + TS.MONEY_FREIGHT17 - TD.MONEY_DEPOSIT_ADJ17) ADJUST17 ,SUM(TS.MONEY_ADJUST18 + TS.MONEY_FREIGHT18 - TD.MONEY_DEPOSIT_ADJ18) ADJUST18 ,SUM(TS.MONEY_ADJUST19 + TS.MONEY_FREIGHT19 - TD.MONEY_DEPOSIT_ADJ19) ADJUST19 ,SUM(TS.MONEY_ADJUST20 + TS.MONEY_FREIGHT20 - TD.MONEY_DEPOSIT_ADJ20) ADJUST20 ,SUM(TS.MONEY_ADJUST21 + TS.MONEY_FREIGHT21 - TD.MONEY_DEPOSIT_ADJ21) ADJUST21 ,SUM(TS.MONEY_ADJUST22 + TS.MONEY_FREIGHT22 - TD.MONEY_DEPOSIT_ADJ22) ADJUST22 ,SUM(TS.MONEY_ADJUST23 + TS.MONEY_FREIGHT23 - TD.MONEY_DEPOSIT_ADJ23) ADJUST23 ,SUM(TS.MONEY_ADJUST24 + TS.MONEY_FREIGHT24 - TD.MONEY_DEPOSIT_ADJ24) ADJUST24 ,SUM(TS.MONEY_ADJUST25 + TS.MONEY_FREIGHT25 - TD.MONEY_DEPOSIT_ADJ25) ADJUST25 ,SUM(TS.MONEY_ADJUST26 + TS.MONEY_FREIGHT26 - TD.MONEY_DEPOSIT_ADJ26) ADJUST26 ,SUM(TS.MONEY_ADJUST27 + TS.MONEY_FREIGHT27 - TD.MONEY_DEPOSIT_ADJ27) ADJUST27 ,SUM(TS.MONEY_ADJUST28 + TS.MONEY_FREIGHT28 - TD.MONEY_DEPOSIT_ADJ28) ADJUST28 ,SUM(TS.MONEY_ADJUST29 + TS.MONEY_FREIGHT29 - TD.MONEY_DEPOSIT_ADJ29) ADJUST29 ,SUM(TS.MONEY_ADJUST30 + TS.MONEY_FREIGHT30 - TD.MONEY_DEPOSIT_ADJ30) ADJUST30 ,SUM(TS.MONEY_ADJUST31 + TS.MONEY_FREIGHT31 - TD.MONEY_DEPOSIT_ADJ31) ADJUST31 -- 調整額は売上調整額と伝票の運賃と入金調整額とする。 -- 日別の伝票調整額 + 日別の運賃 - 日別の入金調整額 -- 前月21日〜末までの売上 ,SUM(TS_PRE.WEIGHT_SALE) WEIGHT_SALE_PRE ,SUM(TS_PRE.MONEY_SALE) MONEY_SALE_PRE ,SUM(TS_PRE.TAX) TAX_PRE ,(SUM(TS_PRE.MONEY_ADJUST) + SUM(TS_PRE.MONEY_FREIGHT) - SUM(TD_PRE.MONEY_DEPOSIT_ADJ)) ADJUST_PRE -- 前月21日〜末までの入金 ,SUM(TD_PRE.MONEY_DEPOSIT) MONEY_DEPOSIT_PRE FROM m_customer mc LEFT OUTER JOIN ( SELECT TS02.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,SUM(TS02.WEIGHT_SALE01) WEIGHT_SALE01 ,SUM(TS02.WEIGHT_SALE02) WEIGHT_SALE02 ,SUM(TS02.WEIGHT_SALE03) WEIGHT_SALE03 ,SUM(TS02.WEIGHT_SALE04) WEIGHT_SALE04 ,SUM(TS02.WEIGHT_SALE05) WEIGHT_SALE05 ,SUM(TS02.WEIGHT_SALE06) WEIGHT_SALE06 ,SUM(TS02.WEIGHT_SALE07) WEIGHT_SALE07 ,SUM(TS02.WEIGHT_SALE08) WEIGHT_SALE08 ,SUM(TS02.WEIGHT_SALE09) WEIGHT_SALE09 ,SUM(TS02.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS02.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS02.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS02.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS02.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS02.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS02.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS02.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS02.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS02.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS02.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS02.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS02.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS02.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS02.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS02.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS02.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS02.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS02.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS02.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS02.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS02.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS02.MONEY_SALE01) MONEY_SALE01 ,SUM(TS02.MONEY_SALE02) MONEY_SALE02 ,SUM(TS02.MONEY_SALE03) MONEY_SALE03 ,SUM(TS02.MONEY_SALE04) MONEY_SALE04 ,SUM(TS02.MONEY_SALE05) MONEY_SALE05 ,SUM(TS02.MONEY_SALE06) MONEY_SALE06 ,SUM(TS02.MONEY_SALE07) MONEY_SALE07 ,SUM(TS02.MONEY_SALE08) MONEY_SALE08 ,SUM(TS02.MONEY_SALE09) MONEY_SALE09 ,SUM(TS02.MONEY_SALE10) MONEY_SALE10 ,SUM(TS02.MONEY_SALE11) MONEY_SALE11 ,SUM(TS02.MONEY_SALE12) MONEY_SALE12 ,SUM(TS02.MONEY_SALE13) MONEY_SALE13 ,SUM(TS02.MONEY_SALE14) MONEY_SALE14 ,SUM(TS02.MONEY_SALE15) MONEY_SALE15 ,SUM(TS02.MONEY_SALE16) MONEY_SALE16 ,SUM(TS02.MONEY_SALE17) MONEY_SALE17 ,SUM(TS02.MONEY_SALE18) MONEY_SALE18 ,SUM(TS02.MONEY_SALE19) MONEY_SALE19 ,SUM(TS02.MONEY_SALE20) MONEY_SALE20 ,SUM(TS02.MONEY_SALE21) MONEY_SALE21 ,SUM(TS02.MONEY_SALE22) MONEY_SALE22 ,SUM(TS02.MONEY_SALE23) MONEY_SALE23 ,SUM(TS02.MONEY_SALE24) MONEY_SALE24 ,SUM(TS02.MONEY_SALE25) MONEY_SALE25 ,SUM(TS02.MONEY_SALE26) MONEY_SALE26 ,SUM(TS02.MONEY_SALE27) MONEY_SALE27 ,SUM(TS02.MONEY_SALE28) MONEY_SALE28 ,SUM(TS02.MONEY_SALE29) MONEY_SALE29 ,SUM(TS02.MONEY_SALE30) MONEY_SALE30 ,SUM(TS02.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS02.TAX01) TAX01 ,SUM(TS02.TAX02) TAX02 ,SUM(TS02.TAX03) TAX03 ,SUM(TS02.TAX04) TAX04 ,SUM(TS02.TAX05) TAX05 ,SUM(TS02.TAX06) TAX06 ,SUM(TS02.TAX07) TAX07 ,SUM(TS02.TAX08) TAX08 ,SUM(TS02.TAX09) TAX09 ,SUM(TS02.TAX10) TAX10 ,SUM(TS02.TAX11) TAX11 ,SUM(TS02.TAX12) TAX12 ,SUM(TS02.TAX13) TAX13 ,SUM(TS02.TAX14) TAX14 ,SUM(TS02.TAX15) TAX15 ,SUM(TS02.TAX16) TAX16 ,SUM(TS02.TAX17) TAX17 ,SUM(TS02.TAX18) TAX18 ,SUM(TS02.TAX19) TAX19 ,SUM(TS02.TAX20) TAX20 ,SUM(TS02.TAX21) TAX21 ,SUM(TS02.TAX22) TAX22 ,SUM(TS02.TAX23) TAX23 ,SUM(TS02.TAX24) TAX24 ,SUM(TS02.TAX25) TAX25 ,SUM(TS02.TAX26) TAX26 ,SUM(TS02.TAX27) TAX27 ,SUM(TS02.TAX28) TAX28 ,SUM(TS02.TAX29) TAX29 ,SUM(TS02.TAX30) TAX30 ,SUM(TS02.TAX31) TAX31 -- 日別の伝票調整額 ,SUM(TS02.MONEY_ADJUST01) MONEY_ADJUST01 ,SUM(TS02.MONEY_ADJUST02) MONEY_ADJUST02 ,SUM(TS02.MONEY_ADJUST03) MONEY_ADJUST03 ,SUM(TS02.MONEY_ADJUST04) MONEY_ADJUST04 ,SUM(TS02.MONEY_ADJUST05) MONEY_ADJUST05 ,SUM(TS02.MONEY_ADJUST06) MONEY_ADJUST06 ,SUM(TS02.MONEY_ADJUST07) MONEY_ADJUST07 ,SUM(TS02.MONEY_ADJUST08) MONEY_ADJUST08 ,SUM(TS02.MONEY_ADJUST09) MONEY_ADJUST09 ,SUM(TS02.MONEY_ADJUST10) MONEY_ADJUST10 ,SUM(TS02.MONEY_ADJUST11) MONEY_ADJUST11 ,SUM(TS02.MONEY_ADJUST12) MONEY_ADJUST12 ,SUM(TS02.MONEY_ADJUST13) MONEY_ADJUST13 ,SUM(TS02.MONEY_ADJUST14) MONEY_ADJUST14 ,SUM(TS02.MONEY_ADJUST15) MONEY_ADJUST15 ,SUM(TS02.MONEY_ADJUST16) MONEY_ADJUST16 ,SUM(TS02.MONEY_ADJUST17) MONEY_ADJUST17 ,SUM(TS02.MONEY_ADJUST18) MONEY_ADJUST18 ,SUM(TS02.MONEY_ADJUST19) MONEY_ADJUST19 ,SUM(TS02.MONEY_ADJUST20) MONEY_ADJUST20 ,SUM(TS02.MONEY_ADJUST21) MONEY_ADJUST21 ,SUM(TS02.MONEY_ADJUST22) MONEY_ADJUST22 ,SUM(TS02.MONEY_ADJUST23) MONEY_ADJUST23 ,SUM(TS02.MONEY_ADJUST24) MONEY_ADJUST24 ,SUM(TS02.MONEY_ADJUST25) MONEY_ADJUST25 ,SUM(TS02.MONEY_ADJUST26) MONEY_ADJUST26 ,SUM(TS02.MONEY_ADJUST27) MONEY_ADJUST27 ,SUM(TS02.MONEY_ADJUST28) MONEY_ADJUST28 ,SUM(TS02.MONEY_ADJUST29) MONEY_ADJUST29 ,SUM(TS02.MONEY_ADJUST30) MONEY_ADJUST30 ,SUM(TS02.MONEY_ADJUST31) MONEY_ADJUST31 -- 日別の運賃 ,SUM(TS02.MONEY_FREIGHT01) MONEY_FREIGHT01 ,SUM(TS02.MONEY_FREIGHT02) MONEY_FREIGHT02 ,SUM(TS02.MONEY_FREIGHT03) MONEY_FREIGHT03 ,SUM(TS02.MONEY_FREIGHT04) MONEY_FREIGHT04 ,SUM(TS02.MONEY_FREIGHT05) MONEY_FREIGHT05 ,SUM(TS02.MONEY_FREIGHT06) MONEY_FREIGHT06 ,SUM(TS02.MONEY_FREIGHT07) MONEY_FREIGHT07 ,SUM(TS02.MONEY_FREIGHT08) MONEY_FREIGHT08 ,SUM(TS02.MONEY_FREIGHT09) MONEY_FREIGHT09 ,SUM(TS02.MONEY_FREIGHT10) MONEY_FREIGHT10 ,SUM(TS02.MONEY_FREIGHT11) MONEY_FREIGHT11 ,SUM(TS02.MONEY_FREIGHT12) MONEY_FREIGHT12 ,SUM(TS02.MONEY_FREIGHT13) MONEY_FREIGHT13 ,SUM(TS02.MONEY_FREIGHT14) MONEY_FREIGHT14 ,SUM(TS02.MONEY_FREIGHT15) MONEY_FREIGHT15 ,SUM(TS02.MONEY_FREIGHT16) MONEY_FREIGHT16 ,SUM(TS02.MONEY_FREIGHT17) MONEY_FREIGHT17 ,SUM(TS02.MONEY_FREIGHT18) MONEY_FREIGHT18 ,SUM(TS02.MONEY_FREIGHT19) MONEY_FREIGHT19 ,SUM(TS02.MONEY_FREIGHT20) MONEY_FREIGHT20 ,SUM(TS02.MONEY_FREIGHT21) MONEY_FREIGHT21 ,SUM(TS02.MONEY_FREIGHT22) MONEY_FREIGHT22 ,SUM(TS02.MONEY_FREIGHT23) MONEY_FREIGHT23 ,SUM(TS02.MONEY_FREIGHT24) MONEY_FREIGHT24 ,SUM(TS02.MONEY_FREIGHT25) MONEY_FREIGHT25 ,SUM(TS02.MONEY_FREIGHT26) MONEY_FREIGHT26 ,SUM(TS02.MONEY_FREIGHT27) MONEY_FREIGHT27 ,SUM(TS02.MONEY_FREIGHT28) MONEY_FREIGHT28 ,SUM(TS02.MONEY_FREIGHT29) MONEY_FREIGHT29 ,SUM(TS02.MONEY_FREIGHT30) MONEY_FREIGHT30 ,SUM(TS02.MONEY_FREIGHT31) MONEY_FREIGHT31 FROM (-- 得意先別納品先ごとのデータ SELECT TS01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE31 -- 日別の売上金額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE31 -- 日別の消費税 ,CASE WHEN TS01.DTS_DAY = 01 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX01 ,CASE WHEN TS01.DTS_DAY = 02 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX02 ,CASE WHEN TS01.DTS_DAY = 03 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX03 ,CASE WHEN TS01.DTS_DAY = 04 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX04 ,CASE WHEN TS01.DTS_DAY = 05 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX05 ,CASE WHEN TS01.DTS_DAY = 06 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX06 ,CASE WHEN TS01.DTS_DAY = 07 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX07 ,CASE WHEN TS01.DTS_DAY = 08 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX08 ,CASE WHEN TS01.DTS_DAY = 09 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX09 ,CASE WHEN TS01.DTS_DAY = 10 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX10 ,CASE WHEN TS01.DTS_DAY = 11 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX11 ,CASE WHEN TS01.DTS_DAY = 12 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX12 ,CASE WHEN TS01.DTS_DAY = 13 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX13 ,CASE WHEN TS01.DTS_DAY = 14 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX14 ,CASE WHEN TS01.DTS_DAY = 15 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX15 ,CASE WHEN TS01.DTS_DAY = 16 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX16 ,CASE WHEN TS01.DTS_DAY = 17 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX17 ,CASE WHEN TS01.DTS_DAY = 18 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX18 ,CASE WHEN TS01.DTS_DAY = 19 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX19 ,CASE WHEN TS01.DTS_DAY = 20 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX20 ,CASE WHEN TS01.DTS_DAY = 21 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX21 ,CASE WHEN TS01.DTS_DAY = 22 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX22 ,CASE WHEN TS01.DTS_DAY = 23 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX23 ,CASE WHEN TS01.DTS_DAY = 24 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX24 ,CASE WHEN TS01.DTS_DAY = 25 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX25 ,CASE WHEN TS01.DTS_DAY = 26 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX26 ,CASE WHEN TS01.DTS_DAY = 27 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX27 ,CASE WHEN TS01.DTS_DAY = 28 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX28 ,CASE WHEN TS01.DTS_DAY = 29 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX29 ,CASE WHEN TS01.DTS_DAY = 30 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX30 ,CASE WHEN TS01.DTS_DAY = 31 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX31 -- 日別の伝票調整額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST31 -- 日別の運賃 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT31 FROM T_SALE TS01 WHERE (('&10' = '') OR (TS01.DTS_YEAR = ('&10'::text) ::numeric)) AND (('&11' = '') OR (TS01.DTS_MONTH = ('&11'::text) ::numeric)) AND TS01.FLG_DELETE = 0 and (('&1' = '') OR (TS01.CD_GREAD = ('&1'::text) ::numeric)) ) TS02 GROUP BY TS02.CD_CUSTOMER ) ts ON (MC.CD_CUSTOMER = TS.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT TD02.CD_CUSTOMER CD_CUSTOMER ,SUM(TD02.MONEY_DEPOSIT01) MONEY_DEPOSIT01 ,SUM(TD02.MONEY_DEPOSIT02) MONEY_DEPOSIT02 ,SUM(TD02.MONEY_DEPOSIT03) MONEY_DEPOSIT03 ,SUM(TD02.MONEY_DEPOSIT04) MONEY_DEPOSIT04 ,SUM(TD02.MONEY_DEPOSIT05) MONEY_DEPOSIT05 ,SUM(TD02.MONEY_DEPOSIT06) MONEY_DEPOSIT06 ,SUM(TD02.MONEY_DEPOSIT07) MONEY_DEPOSIT07 ,SUM(TD02.MONEY_DEPOSIT08) MONEY_DEPOSIT08 ,SUM(TD02.MONEY_DEPOSIT09) MONEY_DEPOSIT09 ,SUM(TD02.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD02.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD02.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD02.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD02.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD02.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD02.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD02.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD02.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD02.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD02.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD02.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD02.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD02.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD02.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD02.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD02.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD02.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD02.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD02.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD02.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD02.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 日別の売上調整額 ,SUM(TD02.MONEY_DEPOSIT_ADJ01) MONEY_DEPOSIT_ADJ01 ,SUM(TD02.MONEY_DEPOSIT_ADJ02) MONEY_DEPOSIT_ADJ02 ,SUM(TD02.MONEY_DEPOSIT_ADJ03) MONEY_DEPOSIT_ADJ03 ,SUM(TD02.MONEY_DEPOSIT_ADJ04) MONEY_DEPOSIT_ADJ04 ,SUM(TD02.MONEY_DEPOSIT_ADJ05) MONEY_DEPOSIT_ADJ05 ,SUM(TD02.MONEY_DEPOSIT_ADJ06) MONEY_DEPOSIT_ADJ06 ,SUM(TD02.MONEY_DEPOSIT_ADJ07) MONEY_DEPOSIT_ADJ07 ,SUM(TD02.MONEY_DEPOSIT_ADJ08) MONEY_DEPOSIT_ADJ08 ,SUM(TD02.MONEY_DEPOSIT_ADJ09) MONEY_DEPOSIT_ADJ09 ,SUM(TD02.MONEY_DEPOSIT_ADJ10) MONEY_DEPOSIT_ADJ10 ,SUM(TD02.MONEY_DEPOSIT_ADJ11) MONEY_DEPOSIT_ADJ11 ,SUM(TD02.MONEY_DEPOSIT_ADJ12) MONEY_DEPOSIT_ADJ12 ,SUM(TD02.MONEY_DEPOSIT_ADJ13) MONEY_DEPOSIT_ADJ13 ,SUM(TD02.MONEY_DEPOSIT_ADJ14) MONEY_DEPOSIT_ADJ14 ,SUM(TD02.MONEY_DEPOSIT_ADJ15) MONEY_DEPOSIT_ADJ15 ,SUM(TD02.MONEY_DEPOSIT_ADJ16) MONEY_DEPOSIT_ADJ16 ,SUM(TD02.MONEY_DEPOSIT_ADJ17) MONEY_DEPOSIT_ADJ17 ,SUM(TD02.MONEY_DEPOSIT_ADJ18) MONEY_DEPOSIT_ADJ18 ,SUM(TD02.MONEY_DEPOSIT_ADJ19) MONEY_DEPOSIT_ADJ19 ,SUM(TD02.MONEY_DEPOSIT_ADJ20) MONEY_DEPOSIT_ADJ20 ,SUM(TD02.MONEY_DEPOSIT_ADJ21) MONEY_DEPOSIT_ADJ21 ,SUM(TD02.MONEY_DEPOSIT_ADJ22) MONEY_DEPOSIT_ADJ22 ,SUM(TD02.MONEY_DEPOSIT_ADJ23) MONEY_DEPOSIT_ADJ23 ,SUM(TD02.MONEY_DEPOSIT_ADJ24) MONEY_DEPOSIT_ADJ24 ,SUM(TD02.MONEY_DEPOSIT_ADJ25) MONEY_DEPOSIT_ADJ25 ,SUM(TD02.MONEY_DEPOSIT_ADJ26) MONEY_DEPOSIT_ADJ26 ,SUM(TD02.MONEY_DEPOSIT_ADJ27) MONEY_DEPOSIT_ADJ27 ,SUM(TD02.MONEY_DEPOSIT_ADJ28) MONEY_DEPOSIT_ADJ28 ,SUM(TD02.MONEY_DEPOSIT_ADJ29) MONEY_DEPOSIT_ADJ29 ,SUM(TD02.MONEY_DEPOSIT_ADJ30) MONEY_DEPOSIT_ADJ30 ,SUM(TD02.MONEY_DEPOSIT_ADJ31) MONEY_DEPOSIT_ADJ31 FROM ( SELECT TD01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の入金データ -- 日別の売上入金 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT31 -- 日別の売上調整額 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ31 FROM T_DEPOSIT TD01 WHERE (('&10' = '') OR (TD01.DTS_YEAR = ('&10'::text) ::numeric)) AND (('&11' = '') OR (TD01.DTS_MONTH = ('&11'::text) ::numeric)) AND TD01.DIV_DELETE = 0 ) TD02 GROUP BY TD02.CD_CUSTOMER ) td ON (MC.CD_CUSTOMER = TD.CD_CUSTOMER) LEFT OUTER JOIN (-- 得意先ごとのデータ SELECT CD_CUSTOMER -- 得意先別の売上データ -- 日別の数量 ,SUM(WEIGHT_SALE) WEIGHT_SALE -- 日別の売上金額 ,SUM(MONEY_SALE) MONEY_SALE -- 日別の消費税 ,SUM(TAX) TAX -- 日別の伝票調整額 ,SUM(MONEY_ADJUST) MONEY_ADJUST -- 日別の運賃 ,SUM(MONEY_FREIGHT) MONEY_FREIGHT FROM T_SALE WHERE (('&14' = '') OR (DTS_YEAR = ('&14'::text) ::numeric)) AND (('&12' = '') OR (DTS_MONTH = ('&12'::text) ::numeric)) AND DTS_DAY >= 21 AND DTS_DAY <= 31 AND FLG_DELETE = 0 and (('&1' = '') OR (CD_GREAD = ('&1'::text) ::numeric)) GROUP BY CD_CUSTOMER ) ts_pre ON (MC.CD_CUSTOMER = TS_PRE.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT CD_CUSTOMER -- 得意先別の入金データ -- 日別の売上入金 ,SUM(CASE WHEN DIV_DEPOSIT = 0 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT -- 日別の売上調整額 ,SUM(CASE WHEN DIV_DEPOSIT = 1 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT_ADJ FROM T_DEPOSIT WHERE (('&14' = '') OR (DTS_YEAR = ('&14'::text) ::numeric)) AND (('&12' = '') OR (DTS_MONTH = ('&12'::text) ::numeric)) AND DIV_DELETE = 0 AND DTS_DAY >= 21 AND DTS_DAY <= 31 GROUP BY CD_CUSTOMER ) td_pre ON (MC.CD_CUSTOMER = TD_PRE.CD_CUSTOMER) WHERE (('&4' = '') OR (MC.CD_CUSTOMER >= ('&4'::text) ::numeric)) AND (('&5' = '') OR (MC.CD_CUSTOMER <= ('&5'::text) ::numeric)) AND MC.DT_START = ( SELECT MAX(MC01.DT_START) FROM M_CUSTOMER MC01 WHERE MC01.CD_CUSTOMER = MC.CD_CUSTOMER) GROUP BY MC.CD_CUSTOMER, MC.NAME_CUSTOMER ORDER BY MC.CD_CUSTOMER, MC.NAME_CUSTOMER --************************************************************************** --* 全得意先の売上データを取得 --*  --************************************************************************** [lselectRecords23] SELECT -- 単価 round((CASE WHEN SUM(TS.WEIGHT_SALE01) = 0 THEN SUM(TS.MONEY_SALE01) ELSE SUM(TS.MONEY_SALE01) / SUM(TS.WEIGHT_SALE01) END) ::numeric, 1) UNIT_PRICE_SALE1 ,round((CASE WHEN SUM(TS.WEIGHT_SALE02) = 0 THEN SUM(TS.MONEY_SALE02) ELSE SUM(TS.MONEY_SALE02) / SUM(TS.WEIGHT_SALE02) END) ::numeric, 1) UNIT_PRICE_SALE2 ,round((CASE WHEN SUM(TS.WEIGHT_SALE03) = 0 THEN SUM(TS.MONEY_SALE03) ELSE SUM(TS.MONEY_SALE03) / SUM(TS.WEIGHT_SALE03) END) ::numeric, 1) UNIT_PRICE_SALE3 ,round((CASE WHEN SUM(TS.WEIGHT_SALE04) = 0 THEN SUM(TS.MONEY_SALE04) ELSE SUM(TS.MONEY_SALE04) / SUM(TS.WEIGHT_SALE04) END) ::numeric, 1) UNIT_PRICE_SALE4 ,round((CASE WHEN SUM(TS.WEIGHT_SALE05) = 0 THEN SUM(TS.MONEY_SALE05) ELSE SUM(TS.MONEY_SALE05) / SUM(TS.WEIGHT_SALE05) END) ::numeric, 1) UNIT_PRICE_SALE5 ,round((CASE WHEN SUM(TS.WEIGHT_SALE06) = 0 THEN SUM(TS.MONEY_SALE06) ELSE SUM(TS.MONEY_SALE06) / SUM(TS.WEIGHT_SALE06) END) ::numeric, 1) UNIT_PRICE_SALE6 ,round((CASE WHEN SUM(TS.WEIGHT_SALE07) = 0 THEN SUM(TS.MONEY_SALE07) ELSE SUM(TS.MONEY_SALE07) / SUM(TS.WEIGHT_SALE07) END) ::numeric, 1) UNIT_PRICE_SALE7 ,round((CASE WHEN SUM(TS.WEIGHT_SALE08) = 0 THEN SUM(TS.MONEY_SALE08) ELSE SUM(TS.MONEY_SALE08) / SUM(TS.WEIGHT_SALE08) END) ::numeric, 1) UNIT_PRICE_SALE8 ,round((CASE WHEN SUM(TS.WEIGHT_SALE09) = 0 THEN SUM(TS.MONEY_SALE09) ELSE SUM(TS.MONEY_SALE09) / SUM(TS.WEIGHT_SALE09) END) ::numeric, 1) UNIT_PRICE_SALE9 ,round((CASE WHEN SUM(TS.WEIGHT_SALE10) = 0 THEN SUM(TS.MONEY_SALE10) ELSE SUM(TS.MONEY_SALE10) / SUM(TS.WEIGHT_SALE10) END) ::numeric, 1) UNIT_PRICE_SALE10 ,round((CASE WHEN SUM(TS.WEIGHT_SALE11) = 0 THEN SUM(TS.MONEY_SALE11) ELSE SUM(TS.MONEY_SALE11) / SUM(TS.WEIGHT_SALE11) END) ::numeric, 1) UNIT_PRICE_SALE11 ,round((CASE WHEN SUM(TS.WEIGHT_SALE12) = 0 THEN SUM(TS.MONEY_SALE12) ELSE SUM(TS.MONEY_SALE12) / SUM(TS.WEIGHT_SALE12) END) ::numeric, 1) UNIT_PRICE_SALE12 ,round((CASE WHEN SUM(TS.WEIGHT_SALE13) = 0 THEN SUM(TS.MONEY_SALE13) ELSE SUM(TS.MONEY_SALE13) / SUM(TS.WEIGHT_SALE13) END) ::numeric, 1) UNIT_PRICE_SALE13 ,round((CASE WHEN SUM(TS.WEIGHT_SALE14) = 0 THEN SUM(TS.MONEY_SALE14) ELSE SUM(TS.MONEY_SALE14) / SUM(TS.WEIGHT_SALE14) END) ::numeric, 1) UNIT_PRICE_SALE14 ,round((CASE WHEN SUM(TS.WEIGHT_SALE15) = 0 THEN SUM(TS.MONEY_SALE15) ELSE SUM(TS.MONEY_SALE15) / SUM(TS.WEIGHT_SALE15) END) ::numeric, 1) UNIT_PRICE_SALE15 ,round((CASE WHEN SUM(TS.WEIGHT_SALE16) = 0 THEN SUM(TS.MONEY_SALE16) ELSE SUM(TS.MONEY_SALE16) / SUM(TS.WEIGHT_SALE16) END) ::numeric, 1) UNIT_PRICE_SALE16 ,round((CASE WHEN SUM(TS.WEIGHT_SALE17) = 0 THEN SUM(TS.MONEY_SALE17) ELSE SUM(TS.MONEY_SALE17) / SUM(TS.WEIGHT_SALE17) END) ::numeric, 1) UNIT_PRICE_SALE17 ,round((CASE WHEN SUM(TS.WEIGHT_SALE18) = 0 THEN SUM(TS.MONEY_SALE18) ELSE SUM(TS.MONEY_SALE18) / SUM(TS.WEIGHT_SALE18) END) ::numeric, 1) UNIT_PRICE_SALE18 ,round((CASE WHEN SUM(TS.WEIGHT_SALE19) = 0 THEN SUM(TS.MONEY_SALE19) ELSE SUM(TS.MONEY_SALE19) / SUM(TS.WEIGHT_SALE19) END) ::numeric, 1) UNIT_PRICE_SALE19 ,round((CASE WHEN SUM(TS.WEIGHT_SALE20) = 0 THEN SUM(TS.MONEY_SALE20) ELSE SUM(TS.MONEY_SALE20) / SUM(TS.WEIGHT_SALE20) END) ::numeric, 1) UNIT_PRICE_SALE20 ,round((CASE WHEN SUM(TS.WEIGHT_SALE21) = 0 THEN SUM(TS.MONEY_SALE21) ELSE SUM(TS.MONEY_SALE21) / SUM(TS.WEIGHT_SALE21) END) ::numeric, 1) UNIT_PRICE_SALE21 ,round((CASE WHEN SUM(TS.WEIGHT_SALE22) = 0 THEN SUM(TS.MONEY_SALE22) ELSE SUM(TS.MONEY_SALE22) / SUM(TS.WEIGHT_SALE22) END) ::numeric, 1) UNIT_PRICE_SALE22 ,round((CASE WHEN SUM(TS.WEIGHT_SALE23) = 0 THEN SUM(TS.MONEY_SALE23) ELSE SUM(TS.MONEY_SALE23) / SUM(TS.WEIGHT_SALE23) END) ::numeric, 1) UNIT_PRICE_SALE23 ,round((CASE WHEN SUM(TS.WEIGHT_SALE24) = 0 THEN SUM(TS.MONEY_SALE24) ELSE SUM(TS.MONEY_SALE24) / SUM(TS.WEIGHT_SALE24) END) ::numeric, 1) UNIT_PRICE_SALE24 ,round((CASE WHEN SUM(TS.WEIGHT_SALE25) = 0 THEN SUM(TS.MONEY_SALE25) ELSE SUM(TS.MONEY_SALE25) / SUM(TS.WEIGHT_SALE25) END) ::numeric, 1) UNIT_PRICE_SALE25 ,round((CASE WHEN SUM(TS.WEIGHT_SALE26) = 0 THEN SUM(TS.MONEY_SALE26) ELSE SUM(TS.MONEY_SALE26) / SUM(TS.WEIGHT_SALE26) END) ::numeric, 1) UNIT_PRICE_SALE26 ,round((CASE WHEN SUM(TS.WEIGHT_SALE27) = 0 THEN SUM(TS.MONEY_SALE27) ELSE SUM(TS.MONEY_SALE27) / SUM(TS.WEIGHT_SALE27) END) ::numeric, 1) UNIT_PRICE_SALE27 ,round((CASE WHEN SUM(TS.WEIGHT_SALE28) = 0 THEN SUM(TS.MONEY_SALE28) ELSE SUM(TS.MONEY_SALE28) / SUM(TS.WEIGHT_SALE28) END) ::numeric, 1) UNIT_PRICE_SALE28 ,round((CASE WHEN SUM(TS.WEIGHT_SALE29) = 0 THEN SUM(TS.MONEY_SALE29) ELSE SUM(TS.MONEY_SALE29) / SUM(TS.WEIGHT_SALE29) END) ::numeric, 1) UNIT_PRICE_SALE29 ,round((CASE WHEN SUM(TS.WEIGHT_SALE30) = 0 THEN SUM(TS.MONEY_SALE30) ELSE SUM(TS.MONEY_SALE30) / SUM(TS.WEIGHT_SALE30) END) ::numeric, 1) UNIT_PRICE_SALE30 ,round((CASE WHEN SUM(TS.WEIGHT_SALE31) = 0 THEN SUM(TS.MONEY_SALE31) ELSE SUM(TS.MONEY_SALE31) / SUM(TS.WEIGHT_SALE31) END) ::numeric, 1) UNIT_PRICE_SALE31 -- 日別の数量 ,SUM(TS.WEIGHT_SALE01) WEIGHT_SALE1 ,SUM(TS.WEIGHT_SALE02) WEIGHT_SALE2 ,SUM(TS.WEIGHT_SALE03) WEIGHT_SALE3 ,SUM(TS.WEIGHT_SALE04) WEIGHT_SALE4 ,SUM(TS.WEIGHT_SALE05) WEIGHT_SALE5 ,SUM(TS.WEIGHT_SALE06) WEIGHT_SALE6 ,SUM(TS.WEIGHT_SALE07) WEIGHT_SALE7 ,SUM(TS.WEIGHT_SALE08) WEIGHT_SALE8 ,SUM(TS.WEIGHT_SALE09) WEIGHT_SALE9 ,SUM(TS.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS.MONEY_SALE01) MONEY_SALE1 ,SUM(TS.MONEY_SALE02) MONEY_SALE2 ,SUM(TS.MONEY_SALE03) MONEY_SALE3 ,SUM(TS.MONEY_SALE04) MONEY_SALE4 ,SUM(TS.MONEY_SALE05) MONEY_SALE5 ,SUM(TS.MONEY_SALE06) MONEY_SALE6 ,SUM(TS.MONEY_SALE07) MONEY_SALE7 ,SUM(TS.MONEY_SALE08) MONEY_SALE8 ,SUM(TS.MONEY_SALE09) MONEY_SALE9 ,SUM(TS.MONEY_SALE10) MONEY_SALE10 ,SUM(TS.MONEY_SALE11) MONEY_SALE11 ,SUM(TS.MONEY_SALE12) MONEY_SALE12 ,SUM(TS.MONEY_SALE13) MONEY_SALE13 ,SUM(TS.MONEY_SALE14) MONEY_SALE14 ,SUM(TS.MONEY_SALE15) MONEY_SALE15 ,SUM(TS.MONEY_SALE16) MONEY_SALE16 ,SUM(TS.MONEY_SALE17) MONEY_SALE17 ,SUM(TS.MONEY_SALE18) MONEY_SALE18 ,SUM(TS.MONEY_SALE19) MONEY_SALE19 ,SUM(TS.MONEY_SALE20) MONEY_SALE20 ,SUM(TS.MONEY_SALE21) MONEY_SALE21 ,SUM(TS.MONEY_SALE22) MONEY_SALE22 ,SUM(TS.MONEY_SALE23) MONEY_SALE23 ,SUM(TS.MONEY_SALE24) MONEY_SALE24 ,SUM(TS.MONEY_SALE25) MONEY_SALE25 ,SUM(TS.MONEY_SALE26) MONEY_SALE26 ,SUM(TS.MONEY_SALE27) MONEY_SALE27 ,SUM(TS.MONEY_SALE28) MONEY_SALE28 ,SUM(TS.MONEY_SALE29) MONEY_SALE29 ,SUM(TS.MONEY_SALE30) MONEY_SALE30 ,SUM(TS.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS.TAX01) TAX1 ,SUM(TS.TAX02) TAX2 ,SUM(TS.TAX03) TAX3 ,SUM(TS.TAX04) TAX4 ,SUM(TS.TAX05) TAX5 ,SUM(TS.TAX06) TAX6 ,SUM(TS.TAX07) TAX7 ,SUM(TS.TAX08) TAX8 ,SUM(TS.TAX09) TAX9 ,SUM(TS.TAX10) TAX10 ,SUM(TS.TAX11) TAX11 ,SUM(TS.TAX12) TAX12 ,SUM(TS.TAX13) TAX13 ,SUM(TS.TAX14) TAX14 ,SUM(TS.TAX15) TAX15 ,SUM(TS.TAX16) TAX16 ,SUM(TS.TAX17) TAX17 ,SUM(TS.TAX18) TAX18 ,SUM(TS.TAX19) TAX19 ,SUM(TS.TAX20) TAX20 ,SUM(TS.TAX21) TAX21 ,SUM(TS.TAX22) TAX22 ,SUM(TS.TAX23) TAX23 ,SUM(TS.TAX24) TAX24 ,SUM(TS.TAX25) TAX25 ,SUM(TS.TAX26) TAX26 ,SUM(TS.TAX27) TAX27 ,SUM(TS.TAX28) TAX28 ,SUM(TS.TAX29) TAX29 ,SUM(TS.TAX30) TAX30 ,SUM(TS.TAX31) TAX31 -- 日別の入金額 ,SUM(TD.MONEY_DEPOSIT01) MONEY_DEPOSIT1 ,SUM(TD.MONEY_DEPOSIT02) MONEY_DEPOSIT2 ,SUM(TD.MONEY_DEPOSIT03) MONEY_DEPOSIT3 ,SUM(TD.MONEY_DEPOSIT04) MONEY_DEPOSIT4 ,SUM(TD.MONEY_DEPOSIT05) MONEY_DEPOSIT5 ,SUM(TD.MONEY_DEPOSIT06) MONEY_DEPOSIT6 ,SUM(TD.MONEY_DEPOSIT07) MONEY_DEPOSIT7 ,SUM(TD.MONEY_DEPOSIT08) MONEY_DEPOSIT8 ,SUM(TD.MONEY_DEPOSIT09) MONEY_DEPOSIT9 ,SUM(TD.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 調整額は売上調整額と伝票の運賃と入金調整額とする。 -- 日別の伝票調整額 + 日別の運賃 - 日別の入金調整額 ,SUM(TS.MONEY_ADJUST01 + TS.MONEY_FREIGHT01 - TD.MONEY_DEPOSIT_ADJ01) ADJUST1 ,SUM(TS.MONEY_ADJUST02 + TS.MONEY_FREIGHT02 - TD.MONEY_DEPOSIT_ADJ02) ADJUST2 ,SUM(TS.MONEY_ADJUST03 + TS.MONEY_FREIGHT03 - TD.MONEY_DEPOSIT_ADJ03) ADJUST3 ,SUM(TS.MONEY_ADJUST04 + TS.MONEY_FREIGHT04 - TD.MONEY_DEPOSIT_ADJ04) ADJUST4 ,SUM(TS.MONEY_ADJUST05 + TS.MONEY_FREIGHT05 - TD.MONEY_DEPOSIT_ADJ05) ADJUST5 ,SUM(TS.MONEY_ADJUST06 + TS.MONEY_FREIGHT06 - TD.MONEY_DEPOSIT_ADJ06) ADJUST6 ,SUM(TS.MONEY_ADJUST07 + TS.MONEY_FREIGHT07 - TD.MONEY_DEPOSIT_ADJ07) ADJUST7 ,SUM(TS.MONEY_ADJUST08 + TS.MONEY_FREIGHT08 - TD.MONEY_DEPOSIT_ADJ08) ADJUST8 ,SUM(TS.MONEY_ADJUST09 + TS.MONEY_FREIGHT09 - TD.MONEY_DEPOSIT_ADJ09) ADJUST9 ,SUM(TS.MONEY_ADJUST10 + TS.MONEY_FREIGHT10 - TD.MONEY_DEPOSIT_ADJ10) ADJUST10 ,SUM(TS.MONEY_ADJUST11 + TS.MONEY_FREIGHT11 - TD.MONEY_DEPOSIT_ADJ11) ADJUST11 ,SUM(TS.MONEY_ADJUST12 + TS.MONEY_FREIGHT12 - TD.MONEY_DEPOSIT_ADJ12) ADJUST12 ,SUM(TS.MONEY_ADJUST13 + TS.MONEY_FREIGHT13 - TD.MONEY_DEPOSIT_ADJ13) ADJUST13 ,SUM(TS.MONEY_ADJUST14 + TS.MONEY_FREIGHT14 - TD.MONEY_DEPOSIT_ADJ14) ADJUST14 ,SUM(TS.MONEY_ADJUST15 + TS.MONEY_FREIGHT15 - TD.MONEY_DEPOSIT_ADJ15) ADJUST15 ,SUM(TS.MONEY_ADJUST16 + TS.MONEY_FREIGHT16 - TD.MONEY_DEPOSIT_ADJ16) ADJUST16 ,SUM(TS.MONEY_ADJUST17 + TS.MONEY_FREIGHT17 - TD.MONEY_DEPOSIT_ADJ17) ADJUST17 ,SUM(TS.MONEY_ADJUST18 + TS.MONEY_FREIGHT18 - TD.MONEY_DEPOSIT_ADJ18) ADJUST18 ,SUM(TS.MONEY_ADJUST19 + TS.MONEY_FREIGHT19 - TD.MONEY_DEPOSIT_ADJ19) ADJUST19 ,SUM(TS.MONEY_ADJUST20 + TS.MONEY_FREIGHT20 - TD.MONEY_DEPOSIT_ADJ20) ADJUST20 ,SUM(TS.MONEY_ADJUST21 + TS.MONEY_FREIGHT21 - TD.MONEY_DEPOSIT_ADJ21) ADJUST21 ,SUM(TS.MONEY_ADJUST22 + TS.MONEY_FREIGHT22 - TD.MONEY_DEPOSIT_ADJ22) ADJUST22 ,SUM(TS.MONEY_ADJUST23 + TS.MONEY_FREIGHT23 - TD.MONEY_DEPOSIT_ADJ23) ADJUST23 ,SUM(TS.MONEY_ADJUST24 + TS.MONEY_FREIGHT24 - TD.MONEY_DEPOSIT_ADJ24) ADJUST24 ,SUM(TS.MONEY_ADJUST25 + TS.MONEY_FREIGHT25 - TD.MONEY_DEPOSIT_ADJ25) ADJUST25 ,SUM(TS.MONEY_ADJUST26 + TS.MONEY_FREIGHT26 - TD.MONEY_DEPOSIT_ADJ26) ADJUST26 ,SUM(TS.MONEY_ADJUST27 + TS.MONEY_FREIGHT27 - TD.MONEY_DEPOSIT_ADJ27) ADJUST27 ,SUM(TS.MONEY_ADJUST28 + TS.MONEY_FREIGHT28 - TD.MONEY_DEPOSIT_ADJ28) ADJUST28 ,SUM(TS.MONEY_ADJUST29 + TS.MONEY_FREIGHT29 - TD.MONEY_DEPOSIT_ADJ29) ADJUST29 ,SUM(TS.MONEY_ADJUST30 + TS.MONEY_FREIGHT30 - TD.MONEY_DEPOSIT_ADJ30) ADJUST30 ,SUM(TS.MONEY_ADJUST31 + TS.MONEY_FREIGHT31 - TD.MONEY_DEPOSIT_ADJ31) ADJUST31 -- 前月21日〜末までの売上 ,SUM(TS_PRE.WEIGHT_SALE) WEIGHT_SALE_PRE ,SUM(TS_PRE.MONEY_SALE) MONEY_SALE_PRE ,SUM(TS_PRE.TAX) TAX_PRE ,(SUM(TS_PRE.MONEY_ADJUST) + SUM(TS_PRE.MONEY_FREIGHT) - SUM(TD_PRE.MONEY_DEPOSIT_ADJ)) ADJUST_PRE -- 前月21日〜末までの入金 ,SUM(TD_PRE.MONEY_DEPOSIT) MONEY_DEPOSIT_PRE FROM m_customer mc LEFT OUTER JOIN (-- 得意先ごとのデータ SELECT CD_CUSTOMER -- 得意先別の売上データ -- 日別の数量 ,SUM(WEIGHT_SALE) WEIGHT_SALE -- 日別の売上金額 ,SUM(MONEY_SALE) MONEY_SALE -- 日別の消費税 ,SUM(TAX) TAX -- 日別の伝票調整額 ,SUM(MONEY_ADJUST) MONEY_ADJUST -- 日別の運賃 ,SUM(MONEY_FREIGHT) MONEY_FREIGHT FROM T_SALE WHERE (('&14' = '') OR (DTS_YEAR = ('&14'::text) ::numeric)) AND (('&12' = '') OR (DTS_MONTH = ('&12'::text) ::numeric)) AND DTS_DAY >= 21 AND DTS_DAY <= 31 AND FLG_DELETE = 0 and (('&1' = '') OR (CD_GREAD = ('&1'::text) ::numeric)) GROUP BY CD_CUSTOMER ) ts_pre ON (MC.CD_CUSTOMER = TS_PRE.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT CD_CUSTOMER -- 得意先別の入金データ -- 日別の売上入金 ,SUM(CASE WHEN DIV_DEPOSIT = 0 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT -- 日別の売上調整額 ,SUM(CASE WHEN DIV_DEPOSIT = 1 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT_ADJ FROM T_DEPOSIT WHERE (('&14' = '') OR (DTS_YEAR = ('&14'::text) ::numeric)) AND (('&12' = '') OR (DTS_MONTH = ('&12'::text) ::numeric)) AND DIV_DELETE = 0 AND DTS_DAY >= 21 AND DTS_DAY <= 31 GROUP BY CD_CUSTOMER ) td_pre ON (MC.CD_CUSTOMER = TD_PRE.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT TS02.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,SUM(TS02.WEIGHT_SALE01) WEIGHT_SALE01 ,SUM(TS02.WEIGHT_SALE02) WEIGHT_SALE02 ,SUM(TS02.WEIGHT_SALE03) WEIGHT_SALE03 ,SUM(TS02.WEIGHT_SALE04) WEIGHT_SALE04 ,SUM(TS02.WEIGHT_SALE05) WEIGHT_SALE05 ,SUM(TS02.WEIGHT_SALE06) WEIGHT_SALE06 ,SUM(TS02.WEIGHT_SALE07) WEIGHT_SALE07 ,SUM(TS02.WEIGHT_SALE08) WEIGHT_SALE08 ,SUM(TS02.WEIGHT_SALE09) WEIGHT_SALE09 ,SUM(TS02.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS02.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS02.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS02.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS02.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS02.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS02.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS02.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS02.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS02.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS02.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS02.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS02.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS02.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS02.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS02.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS02.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS02.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS02.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS02.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS02.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS02.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS02.MONEY_SALE01) MONEY_SALE01 ,SUM(TS02.MONEY_SALE02) MONEY_SALE02 ,SUM(TS02.MONEY_SALE03) MONEY_SALE03 ,SUM(TS02.MONEY_SALE04) MONEY_SALE04 ,SUM(TS02.MONEY_SALE05) MONEY_SALE05 ,SUM(TS02.MONEY_SALE06) MONEY_SALE06 ,SUM(TS02.MONEY_SALE07) MONEY_SALE07 ,SUM(TS02.MONEY_SALE08) MONEY_SALE08 ,SUM(TS02.MONEY_SALE09) MONEY_SALE09 ,SUM(TS02.MONEY_SALE10) MONEY_SALE10 ,SUM(TS02.MONEY_SALE11) MONEY_SALE11 ,SUM(TS02.MONEY_SALE12) MONEY_SALE12 ,SUM(TS02.MONEY_SALE13) MONEY_SALE13 ,SUM(TS02.MONEY_SALE14) MONEY_SALE14 ,SUM(TS02.MONEY_SALE15) MONEY_SALE15 ,SUM(TS02.MONEY_SALE16) MONEY_SALE16 ,SUM(TS02.MONEY_SALE17) MONEY_SALE17 ,SUM(TS02.MONEY_SALE18) MONEY_SALE18 ,SUM(TS02.MONEY_SALE19) MONEY_SALE19 ,SUM(TS02.MONEY_SALE20) MONEY_SALE20 ,SUM(TS02.MONEY_SALE21) MONEY_SALE21 ,SUM(TS02.MONEY_SALE22) MONEY_SALE22 ,SUM(TS02.MONEY_SALE23) MONEY_SALE23 ,SUM(TS02.MONEY_SALE24) MONEY_SALE24 ,SUM(TS02.MONEY_SALE25) MONEY_SALE25 ,SUM(TS02.MONEY_SALE26) MONEY_SALE26 ,SUM(TS02.MONEY_SALE27) MONEY_SALE27 ,SUM(TS02.MONEY_SALE28) MONEY_SALE28 ,SUM(TS02.MONEY_SALE29) MONEY_SALE29 ,SUM(TS02.MONEY_SALE30) MONEY_SALE30 ,SUM(TS02.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS02.TAX01) TAX01 ,SUM(TS02.TAX02) TAX02 ,SUM(TS02.TAX03) TAX03 ,SUM(TS02.TAX04) TAX04 ,SUM(TS02.TAX05) TAX05 ,SUM(TS02.TAX06) TAX06 ,SUM(TS02.TAX07) TAX07 ,SUM(TS02.TAX08) TAX08 ,SUM(TS02.TAX09) TAX09 ,SUM(TS02.TAX10) TAX10 ,SUM(TS02.TAX11) TAX11 ,SUM(TS02.TAX12) TAX12 ,SUM(TS02.TAX13) TAX13 ,SUM(TS02.TAX14) TAX14 ,SUM(TS02.TAX15) TAX15 ,SUM(TS02.TAX16) TAX16 ,SUM(TS02.TAX17) TAX17 ,SUM(TS02.TAX18) TAX18 ,SUM(TS02.TAX19) TAX19 ,SUM(TS02.TAX20) TAX20 ,SUM(TS02.TAX21) TAX21 ,SUM(TS02.TAX22) TAX22 ,SUM(TS02.TAX23) TAX23 ,SUM(TS02.TAX24) TAX24 ,SUM(TS02.TAX25) TAX25 ,SUM(TS02.TAX26) TAX26 ,SUM(TS02.TAX27) TAX27 ,SUM(TS02.TAX28) TAX28 ,SUM(TS02.TAX29) TAX29 ,SUM(TS02.TAX30) TAX30 ,SUM(TS02.TAX31) TAX31 -- 日別の伝票調整額 ,SUM(TS02.MONEY_ADJUST01) MONEY_ADJUST01 ,SUM(TS02.MONEY_ADJUST02) MONEY_ADJUST02 ,SUM(TS02.MONEY_ADJUST03) MONEY_ADJUST03 ,SUM(TS02.MONEY_ADJUST04) MONEY_ADJUST04 ,SUM(TS02.MONEY_ADJUST05) MONEY_ADJUST05 ,SUM(TS02.MONEY_ADJUST06) MONEY_ADJUST06 ,SUM(TS02.MONEY_ADJUST07) MONEY_ADJUST07 ,SUM(TS02.MONEY_ADJUST08) MONEY_ADJUST08 ,SUM(TS02.MONEY_ADJUST09) MONEY_ADJUST09 ,SUM(TS02.MONEY_ADJUST10) MONEY_ADJUST10 ,SUM(TS02.MONEY_ADJUST11) MONEY_ADJUST11 ,SUM(TS02.MONEY_ADJUST12) MONEY_ADJUST12 ,SUM(TS02.MONEY_ADJUST13) MONEY_ADJUST13 ,SUM(TS02.MONEY_ADJUST14) MONEY_ADJUST14 ,SUM(TS02.MONEY_ADJUST15) MONEY_ADJUST15 ,SUM(TS02.MONEY_ADJUST16) MONEY_ADJUST16 ,SUM(TS02.MONEY_ADJUST17) MONEY_ADJUST17 ,SUM(TS02.MONEY_ADJUST18) MONEY_ADJUST18 ,SUM(TS02.MONEY_ADJUST19) MONEY_ADJUST19 ,SUM(TS02.MONEY_ADJUST20) MONEY_ADJUST20 ,SUM(TS02.MONEY_ADJUST21) MONEY_ADJUST21 ,SUM(TS02.MONEY_ADJUST22) MONEY_ADJUST22 ,SUM(TS02.MONEY_ADJUST23) MONEY_ADJUST23 ,SUM(TS02.MONEY_ADJUST24) MONEY_ADJUST24 ,SUM(TS02.MONEY_ADJUST25) MONEY_ADJUST25 ,SUM(TS02.MONEY_ADJUST26) MONEY_ADJUST26 ,SUM(TS02.MONEY_ADJUST27) MONEY_ADJUST27 ,SUM(TS02.MONEY_ADJUST28) MONEY_ADJUST28 ,SUM(TS02.MONEY_ADJUST29) MONEY_ADJUST29 ,SUM(TS02.MONEY_ADJUST30) MONEY_ADJUST30 ,SUM(TS02.MONEY_ADJUST31) MONEY_ADJUST31 -- 日別の運賃 ,SUM(TS02.MONEY_FREIGHT01) MONEY_FREIGHT01 ,SUM(TS02.MONEY_FREIGHT02) MONEY_FREIGHT02 ,SUM(TS02.MONEY_FREIGHT03) MONEY_FREIGHT03 ,SUM(TS02.MONEY_FREIGHT04) MONEY_FREIGHT04 ,SUM(TS02.MONEY_FREIGHT05) MONEY_FREIGHT05 ,SUM(TS02.MONEY_FREIGHT06) MONEY_FREIGHT06 ,SUM(TS02.MONEY_FREIGHT07) MONEY_FREIGHT07 ,SUM(TS02.MONEY_FREIGHT08) MONEY_FREIGHT08 ,SUM(TS02.MONEY_FREIGHT09) MONEY_FREIGHT09 ,SUM(TS02.MONEY_FREIGHT10) MONEY_FREIGHT10 ,SUM(TS02.MONEY_FREIGHT11) MONEY_FREIGHT11 ,SUM(TS02.MONEY_FREIGHT12) MONEY_FREIGHT12 ,SUM(TS02.MONEY_FREIGHT13) MONEY_FREIGHT13 ,SUM(TS02.MONEY_FREIGHT14) MONEY_FREIGHT14 ,SUM(TS02.MONEY_FREIGHT15) MONEY_FREIGHT15 ,SUM(TS02.MONEY_FREIGHT16) MONEY_FREIGHT16 ,SUM(TS02.MONEY_FREIGHT17) MONEY_FREIGHT17 ,SUM(TS02.MONEY_FREIGHT18) MONEY_FREIGHT18 ,SUM(TS02.MONEY_FREIGHT19) MONEY_FREIGHT19 ,SUM(TS02.MONEY_FREIGHT20) MONEY_FREIGHT20 ,SUM(TS02.MONEY_FREIGHT21) MONEY_FREIGHT21 ,SUM(TS02.MONEY_FREIGHT22) MONEY_FREIGHT22 ,SUM(TS02.MONEY_FREIGHT23) MONEY_FREIGHT23 ,SUM(TS02.MONEY_FREIGHT24) MONEY_FREIGHT24 ,SUM(TS02.MONEY_FREIGHT25) MONEY_FREIGHT25 ,SUM(TS02.MONEY_FREIGHT26) MONEY_FREIGHT26 ,SUM(TS02.MONEY_FREIGHT27) MONEY_FREIGHT27 ,SUM(TS02.MONEY_FREIGHT28) MONEY_FREIGHT28 ,SUM(TS02.MONEY_FREIGHT29) MONEY_FREIGHT29 ,SUM(TS02.MONEY_FREIGHT30) MONEY_FREIGHT30 ,SUM(TS02.MONEY_FREIGHT31) MONEY_FREIGHT31 FROM (-- 得意先別納品先ごとのデータ SELECT TS01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE31 -- 日別の売上金額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE31 -- 日別の消費税 ,CASE WHEN TS01.DTS_DAY = 01 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX01 ,CASE WHEN TS01.DTS_DAY = 02 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX02 ,CASE WHEN TS01.DTS_DAY = 03 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX03 ,CASE WHEN TS01.DTS_DAY = 04 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX04 ,CASE WHEN TS01.DTS_DAY = 05 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX05 ,CASE WHEN TS01.DTS_DAY = 06 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX06 ,CASE WHEN TS01.DTS_DAY = 07 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX07 ,CASE WHEN TS01.DTS_DAY = 08 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX08 ,CASE WHEN TS01.DTS_DAY = 09 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX09 ,CASE WHEN TS01.DTS_DAY = 10 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX10 ,CASE WHEN TS01.DTS_DAY = 11 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX11 ,CASE WHEN TS01.DTS_DAY = 12 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX12 ,CASE WHEN TS01.DTS_DAY = 13 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX13 ,CASE WHEN TS01.DTS_DAY = 14 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX14 ,CASE WHEN TS01.DTS_DAY = 15 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX15 ,CASE WHEN TS01.DTS_DAY = 16 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX16 ,CASE WHEN TS01.DTS_DAY = 17 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX17 ,CASE WHEN TS01.DTS_DAY = 18 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX18 ,CASE WHEN TS01.DTS_DAY = 19 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX19 ,CASE WHEN TS01.DTS_DAY = 20 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX20 ,CASE WHEN TS01.DTS_DAY = 21 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX21 ,CASE WHEN TS01.DTS_DAY = 22 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX22 ,CASE WHEN TS01.DTS_DAY = 23 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX23 ,CASE WHEN TS01.DTS_DAY = 24 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX24 ,CASE WHEN TS01.DTS_DAY = 25 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX25 ,CASE WHEN TS01.DTS_DAY = 26 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX26 ,CASE WHEN TS01.DTS_DAY = 27 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX27 ,CASE WHEN TS01.DTS_DAY = 28 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX28 ,CASE WHEN TS01.DTS_DAY = 29 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX29 ,CASE WHEN TS01.DTS_DAY = 30 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX30 ,CASE WHEN TS01.DTS_DAY = 31 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX31 -- 日別の伝票調整額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST31 -- 日別の運賃 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT31 FROM T_SALE TS01 WHERE (('&10' = '') OR (TS01.DTS_YEAR = ('&10'::text) ::numeric)) AND (('&11' = '') OR (TS01.DTS_MONTH = ('&11'::text) ::numeric)) AND TS01.FLG_DELETE = 0 and (('&1' = '') OR (TS01.CD_GREAD = ('&1'::text) ::numeric)) ) TS02 GROUP BY TS02.CD_CUSTOMER ) ts ON (MC.CD_CUSTOMER = TS.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT TD02.CD_CUSTOMER CD_CUSTOMER ,SUM(TD02.MONEY_DEPOSIT01) MONEY_DEPOSIT01 ,SUM(TD02.MONEY_DEPOSIT02) MONEY_DEPOSIT02 ,SUM(TD02.MONEY_DEPOSIT03) MONEY_DEPOSIT03 ,SUM(TD02.MONEY_DEPOSIT04) MONEY_DEPOSIT04 ,SUM(TD02.MONEY_DEPOSIT05) MONEY_DEPOSIT05 ,SUM(TD02.MONEY_DEPOSIT06) MONEY_DEPOSIT06 ,SUM(TD02.MONEY_DEPOSIT07) MONEY_DEPOSIT07 ,SUM(TD02.MONEY_DEPOSIT08) MONEY_DEPOSIT08 ,SUM(TD02.MONEY_DEPOSIT09) MONEY_DEPOSIT09 ,SUM(TD02.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD02.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD02.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD02.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD02.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD02.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD02.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD02.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD02.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD02.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD02.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD02.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD02.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD02.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD02.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD02.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD02.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD02.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD02.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD02.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD02.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD02.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 日別の売上調整額 ,SUM(TD02.MONEY_DEPOSIT_ADJ01) MONEY_DEPOSIT_ADJ01 ,SUM(TD02.MONEY_DEPOSIT_ADJ02) MONEY_DEPOSIT_ADJ02 ,SUM(TD02.MONEY_DEPOSIT_ADJ03) MONEY_DEPOSIT_ADJ03 ,SUM(TD02.MONEY_DEPOSIT_ADJ04) MONEY_DEPOSIT_ADJ04 ,SUM(TD02.MONEY_DEPOSIT_ADJ05) MONEY_DEPOSIT_ADJ05 ,SUM(TD02.MONEY_DEPOSIT_ADJ06) MONEY_DEPOSIT_ADJ06 ,SUM(TD02.MONEY_DEPOSIT_ADJ07) MONEY_DEPOSIT_ADJ07 ,SUM(TD02.MONEY_DEPOSIT_ADJ08) MONEY_DEPOSIT_ADJ08 ,SUM(TD02.MONEY_DEPOSIT_ADJ09) MONEY_DEPOSIT_ADJ09 ,SUM(TD02.MONEY_DEPOSIT_ADJ10) MONEY_DEPOSIT_ADJ10 ,SUM(TD02.MONEY_DEPOSIT_ADJ11) MONEY_DEPOSIT_ADJ11 ,SUM(TD02.MONEY_DEPOSIT_ADJ12) MONEY_DEPOSIT_ADJ12 ,SUM(TD02.MONEY_DEPOSIT_ADJ13) MONEY_DEPOSIT_ADJ13 ,SUM(TD02.MONEY_DEPOSIT_ADJ14) MONEY_DEPOSIT_ADJ14 ,SUM(TD02.MONEY_DEPOSIT_ADJ15) MONEY_DEPOSIT_ADJ15 ,SUM(TD02.MONEY_DEPOSIT_ADJ16) MONEY_DEPOSIT_ADJ16 ,SUM(TD02.MONEY_DEPOSIT_ADJ17) MONEY_DEPOSIT_ADJ17 ,SUM(TD02.MONEY_DEPOSIT_ADJ18) MONEY_DEPOSIT_ADJ18 ,SUM(TD02.MONEY_DEPOSIT_ADJ19) MONEY_DEPOSIT_ADJ19 ,SUM(TD02.MONEY_DEPOSIT_ADJ20) MONEY_DEPOSIT_ADJ20 ,SUM(TD02.MONEY_DEPOSIT_ADJ21) MONEY_DEPOSIT_ADJ21 ,SUM(TD02.MONEY_DEPOSIT_ADJ22) MONEY_DEPOSIT_ADJ22 ,SUM(TD02.MONEY_DEPOSIT_ADJ23) MONEY_DEPOSIT_ADJ23 ,SUM(TD02.MONEY_DEPOSIT_ADJ24) MONEY_DEPOSIT_ADJ24 ,SUM(TD02.MONEY_DEPOSIT_ADJ25) MONEY_DEPOSIT_ADJ25 ,SUM(TD02.MONEY_DEPOSIT_ADJ26) MONEY_DEPOSIT_ADJ26 ,SUM(TD02.MONEY_DEPOSIT_ADJ27) MONEY_DEPOSIT_ADJ27 ,SUM(TD02.MONEY_DEPOSIT_ADJ28) MONEY_DEPOSIT_ADJ28 ,SUM(TD02.MONEY_DEPOSIT_ADJ29) MONEY_DEPOSIT_ADJ29 ,SUM(TD02.MONEY_DEPOSIT_ADJ30) MONEY_DEPOSIT_ADJ30 ,SUM(TD02.MONEY_DEPOSIT_ADJ31) MONEY_DEPOSIT_ADJ31 FROM ( SELECT TD01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の入金データ -- 日別の売上入金 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT31 -- 日別の売上調整額 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ31 FROM T_DEPOSIT TD01 WHERE (('&10' = '') OR (TD01.DTS_YEAR = ('&10'::text) ::numeric)) AND (('&11' = '') OR (TD01.DTS_MONTH = ('&11'::text) ::numeric)) AND TD01.DIV_DELETE = 0 ) TD02 GROUP BY TD02.CD_CUSTOMER ) td ON (MC.CD_CUSTOMER = TD.CD_CUSTOMER) WHERE MC.DT_START = ( SELECT MAX(MC01.DT_START) FROM M_CUSTOMER MC01 WHERE MC01.CD_CUSTOMER = MC.CD_CUSTOMER) AND (('&4' = '') OR (MC.CD_CUSTOMER >= ('&4'::text) ::numeric)) AND (('&5' = '') OR (MC.CD_CUSTOMER <= ('&5'::text) ::numeric)) --************************************************************************** --* 得意先別の売上データを取得 --* (得意先、別明細取得用) --************************************************************************** [lselectRecords24] SELECT MC.CD_CUSTOMER ,MC.NAME_CUSTOMER -- 単価 ,CASE WHEN SUM(TS.WEIGHT_SALE01) = 0 THEN SUM(TS.MONEY_SALE01) ELSE SUM(TS.MONEY_SALE01) / SUM(TS.WEIGHT_SALE01) END UNIT_PRICE_SALE1 ,CASE WHEN SUM(TS.WEIGHT_SALE02) = 0 THEN SUM(TS.MONEY_SALE02) ELSE SUM(TS.MONEY_SALE02) / SUM(TS.WEIGHT_SALE02) END UNIT_PRICE_SALE2 ,CASE WHEN SUM(TS.WEIGHT_SALE03) = 0 THEN SUM(TS.MONEY_SALE03) ELSE SUM(TS.MONEY_SALE03) / SUM(TS.WEIGHT_SALE03) END UNIT_PRICE_SALE3 ,CASE WHEN SUM(TS.WEIGHT_SALE04) = 0 THEN SUM(TS.MONEY_SALE04) ELSE SUM(TS.MONEY_SALE04) / SUM(TS.WEIGHT_SALE04) END UNIT_PRICE_SALE4 ,CASE WHEN SUM(TS.WEIGHT_SALE05) = 0 THEN SUM(TS.MONEY_SALE05) ELSE SUM(TS.MONEY_SALE05) / SUM(TS.WEIGHT_SALE05) END UNIT_PRICE_SALE5 ,CASE WHEN SUM(TS.WEIGHT_SALE06) = 0 THEN SUM(TS.MONEY_SALE06) ELSE SUM(TS.MONEY_SALE06) / SUM(TS.WEIGHT_SALE06) END UNIT_PRICE_SALE6 ,CASE WHEN SUM(TS.WEIGHT_SALE07) = 0 THEN SUM(TS.MONEY_SALE07) ELSE SUM(TS.MONEY_SALE07) / SUM(TS.WEIGHT_SALE07) END UNIT_PRICE_SALE7 ,CASE WHEN SUM(TS.WEIGHT_SALE08) = 0 THEN SUM(TS.MONEY_SALE08) ELSE SUM(TS.MONEY_SALE08) / SUM(TS.WEIGHT_SALE08) END UNIT_PRICE_SALE8 ,CASE WHEN SUM(TS.WEIGHT_SALE09) = 0 THEN SUM(TS.MONEY_SALE09) ELSE SUM(TS.MONEY_SALE09) / SUM(TS.WEIGHT_SALE09) END UNIT_PRICE_SALE9 ,CASE WHEN SUM(TS.WEIGHT_SALE10) = 0 THEN SUM(TS.MONEY_SALE10) ELSE SUM(TS.MONEY_SALE10) / SUM(TS.WEIGHT_SALE10) END UNIT_PRICE_SALE10 ,CASE WHEN SUM(TS.WEIGHT_SALE11) = 0 THEN SUM(TS.MONEY_SALE11) ELSE SUM(TS.MONEY_SALE11) / SUM(TS.WEIGHT_SALE11) END UNIT_PRICE_SALE11 ,CASE WHEN SUM(TS.WEIGHT_SALE12) = 0 THEN SUM(TS.MONEY_SALE12) ELSE SUM(TS.MONEY_SALE12) / SUM(TS.WEIGHT_SALE12) END UNIT_PRICE_SALE12 ,CASE WHEN SUM(TS.WEIGHT_SALE13) = 0 THEN SUM(TS.MONEY_SALE13) ELSE SUM(TS.MONEY_SALE13) / SUM(TS.WEIGHT_SALE13) END UNIT_PRICE_SALE13 ,CASE WHEN SUM(TS.WEIGHT_SALE14) = 0 THEN SUM(TS.MONEY_SALE14) ELSE SUM(TS.MONEY_SALE14) / SUM(TS.WEIGHT_SALE14) END UNIT_PRICE_SALE14 ,CASE WHEN SUM(TS.WEIGHT_SALE15) = 0 THEN SUM(TS.MONEY_SALE15) ELSE SUM(TS.MONEY_SALE15) / SUM(TS.WEIGHT_SALE15) END UNIT_PRICE_SALE15 ,CASE WHEN SUM(TS.WEIGHT_SALE16) = 0 THEN SUM(TS.MONEY_SALE16) ELSE SUM(TS.MONEY_SALE16) / SUM(TS.WEIGHT_SALE16) END UNIT_PRICE_SALE16 ,CASE WHEN SUM(TS.WEIGHT_SALE17) = 0 THEN SUM(TS.MONEY_SALE17) ELSE SUM(TS.MONEY_SALE17) / SUM(TS.WEIGHT_SALE17) END UNIT_PRICE_SALE17 ,CASE WHEN SUM(TS.WEIGHT_SALE18) = 0 THEN SUM(TS.MONEY_SALE18) ELSE SUM(TS.MONEY_SALE18) / SUM(TS.WEIGHT_SALE18) END UNIT_PRICE_SALE18 ,CASE WHEN SUM(TS.WEIGHT_SALE19) = 0 THEN SUM(TS.MONEY_SALE19) ELSE SUM(TS.MONEY_SALE19) / SUM(TS.WEIGHT_SALE19) END UNIT_PRICE_SALE19 ,CASE WHEN SUM(TS.WEIGHT_SALE20) = 0 THEN SUM(TS.MONEY_SALE20) ELSE SUM(TS.MONEY_SALE20) / SUM(TS.WEIGHT_SALE20) END UNIT_PRICE_SALE20 ,CASE WHEN SUM(TS.WEIGHT_SALE21) = 0 THEN SUM(TS.MONEY_SALE21) ELSE SUM(TS.MONEY_SALE21) / SUM(TS.WEIGHT_SALE21) END UNIT_PRICE_SALE21 ,CASE WHEN SUM(TS.WEIGHT_SALE22) = 0 THEN SUM(TS.MONEY_SALE22) ELSE SUM(TS.MONEY_SALE22) / SUM(TS.WEIGHT_SALE22) END UNIT_PRICE_SALE22 ,CASE WHEN SUM(TS.WEIGHT_SALE23) = 0 THEN SUM(TS.MONEY_SALE23) ELSE SUM(TS.MONEY_SALE23) / SUM(TS.WEIGHT_SALE23) END UNIT_PRICE_SALE23 ,CASE WHEN SUM(TS.WEIGHT_SALE24) = 0 THEN SUM(TS.MONEY_SALE24) ELSE SUM(TS.MONEY_SALE24) / SUM(TS.WEIGHT_SALE24) END UNIT_PRICE_SALE24 ,CASE WHEN SUM(TS.WEIGHT_SALE25) = 0 THEN SUM(TS.MONEY_SALE25) ELSE SUM(TS.MONEY_SALE25) / SUM(TS.WEIGHT_SALE25) END UNIT_PRICE_SALE25 ,CASE WHEN SUM(TS.WEIGHT_SALE26) = 0 THEN SUM(TS.MONEY_SALE26) ELSE SUM(TS.MONEY_SALE26) / SUM(TS.WEIGHT_SALE26) END UNIT_PRICE_SALE26 ,CASE WHEN SUM(TS.WEIGHT_SALE27) = 0 THEN SUM(TS.MONEY_SALE27) ELSE SUM(TS.MONEY_SALE27) / SUM(TS.WEIGHT_SALE27) END UNIT_PRICE_SALE27 ,CASE WHEN SUM(TS.WEIGHT_SALE28) = 0 THEN SUM(TS.MONEY_SALE28) ELSE SUM(TS.MONEY_SALE28) / SUM(TS.WEIGHT_SALE28) END UNIT_PRICE_SALE28 ,CASE WHEN SUM(TS.WEIGHT_SALE29) = 0 THEN SUM(TS.MONEY_SALE29) ELSE SUM(TS.MONEY_SALE29) / SUM(TS.WEIGHT_SALE29) END UNIT_PRICE_SALE29 ,CASE WHEN SUM(TS.WEIGHT_SALE30) = 0 THEN SUM(TS.MONEY_SALE30) ELSE SUM(TS.MONEY_SALE30) / SUM(TS.WEIGHT_SALE30) END UNIT_PRICE_SALE30 ,CASE WHEN SUM(TS.WEIGHT_SALE31) = 0 THEN SUM(TS.MONEY_SALE31) ELSE SUM(TS.MONEY_SALE31) / SUM(TS.WEIGHT_SALE31) END UNIT_PRICE_SALE31 -- 日別の数量 ,SUM(TS.WEIGHT_SALE01) WEIGHT_SALE1 ,SUM(TS.WEIGHT_SALE02) WEIGHT_SALE2 ,SUM(TS.WEIGHT_SALE03) WEIGHT_SALE3 ,SUM(TS.WEIGHT_SALE04) WEIGHT_SALE4 ,SUM(TS.WEIGHT_SALE05) WEIGHT_SALE5 ,SUM(TS.WEIGHT_SALE06) WEIGHT_SALE6 ,SUM(TS.WEIGHT_SALE07) WEIGHT_SALE7 ,SUM(TS.WEIGHT_SALE08) WEIGHT_SALE8 ,SUM(TS.WEIGHT_SALE09) WEIGHT_SALE9 ,SUM(TS.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS.MONEY_SALE01) MONEY_SALE1 ,SUM(TS.MONEY_SALE02) MONEY_SALE2 ,SUM(TS.MONEY_SALE03) MONEY_SALE3 ,SUM(TS.MONEY_SALE04) MONEY_SALE4 ,SUM(TS.MONEY_SALE05) MONEY_SALE5 ,SUM(TS.MONEY_SALE06) MONEY_SALE6 ,SUM(TS.MONEY_SALE07) MONEY_SALE7 ,SUM(TS.MONEY_SALE08) MONEY_SALE8 ,SUM(TS.MONEY_SALE09) MONEY_SALE9 ,SUM(TS.MONEY_SALE10) MONEY_SALE10 ,SUM(TS.MONEY_SALE11) MONEY_SALE11 ,SUM(TS.MONEY_SALE12) MONEY_SALE12 ,SUM(TS.MONEY_SALE13) MONEY_SALE13 ,SUM(TS.MONEY_SALE14) MONEY_SALE14 ,SUM(TS.MONEY_SALE15) MONEY_SALE15 ,SUM(TS.MONEY_SALE16) MONEY_SALE16 ,SUM(TS.MONEY_SALE17) MONEY_SALE17 ,SUM(TS.MONEY_SALE18) MONEY_SALE18 ,SUM(TS.MONEY_SALE19) MONEY_SALE19 ,SUM(TS.MONEY_SALE20) MONEY_SALE20 ,SUM(TS.MONEY_SALE21) MONEY_SALE21 ,SUM(TS.MONEY_SALE22) MONEY_SALE22 ,SUM(TS.MONEY_SALE23) MONEY_SALE23 ,SUM(TS.MONEY_SALE24) MONEY_SALE24 ,SUM(TS.MONEY_SALE25) MONEY_SALE25 ,SUM(TS.MONEY_SALE26) MONEY_SALE26 ,SUM(TS.MONEY_SALE27) MONEY_SALE27 ,SUM(TS.MONEY_SALE28) MONEY_SALE28 ,SUM(TS.MONEY_SALE29) MONEY_SALE29 ,SUM(TS.MONEY_SALE30) MONEY_SALE30 ,SUM(TS.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS.TAX01) TAX1 ,SUM(TS.TAX02) TAX2 ,SUM(TS.TAX03) TAX3 ,SUM(TS.TAX04) TAX4 ,SUM(TS.TAX05) TAX5 ,SUM(TS.TAX06) TAX6 ,SUM(TS.TAX07) TAX7 ,SUM(TS.TAX08) TAX8 ,SUM(TS.TAX09) TAX9 ,SUM(TS.TAX10) TAX10 ,SUM(TS.TAX11) TAX11 ,SUM(TS.TAX12) TAX12 ,SUM(TS.TAX13) TAX13 ,SUM(TS.TAX14) TAX14 ,SUM(TS.TAX15) TAX15 ,SUM(TS.TAX16) TAX16 ,SUM(TS.TAX17) TAX17 ,SUM(TS.TAX18) TAX18 ,SUM(TS.TAX19) TAX19 ,SUM(TS.TAX20) TAX20 ,SUM(TS.TAX21) TAX21 ,SUM(TS.TAX22) TAX22 ,SUM(TS.TAX23) TAX23 ,SUM(TS.TAX24) TAX24 ,SUM(TS.TAX25) TAX25 ,SUM(TS.TAX26) TAX26 ,SUM(TS.TAX27) TAX27 ,SUM(TS.TAX28) TAX28 ,SUM(TS.TAX29) TAX29 ,SUM(TS.TAX30) TAX30 ,SUM(TS.TAX31) TAX31 -- 日別の入金額 ,SUM(TD.MONEY_DEPOSIT01) MONEY_DEPOSIT1 ,SUM(TD.MONEY_DEPOSIT02) MONEY_DEPOSIT2 ,SUM(TD.MONEY_DEPOSIT03) MONEY_DEPOSIT3 ,SUM(TD.MONEY_DEPOSIT04) MONEY_DEPOSIT4 ,SUM(TD.MONEY_DEPOSIT05) MONEY_DEPOSIT5 ,SUM(TD.MONEY_DEPOSIT06) MONEY_DEPOSIT6 ,SUM(TD.MONEY_DEPOSIT07) MONEY_DEPOSIT7 ,SUM(TD.MONEY_DEPOSIT08) MONEY_DEPOSIT8 ,SUM(TD.MONEY_DEPOSIT09) MONEY_DEPOSIT9 ,SUM(TD.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 調整額は売上調整額と伝票の運賃と入金調整額とする。 -- 日別の伝票調整額 + 日別の運賃 - 日別の入金調整額 ,SUM(TS.MONEY_ADJUST01 + TS.MONEY_FREIGHT01 - TD.MONEY_DEPOSIT_ADJ01) ADJUST1 ,SUM(TS.MONEY_ADJUST02 + TS.MONEY_FREIGHT02 - TD.MONEY_DEPOSIT_ADJ02) ADJUST2 ,SUM(TS.MONEY_ADJUST03 + TS.MONEY_FREIGHT03 - TD.MONEY_DEPOSIT_ADJ03) ADJUST3 ,SUM(TS.MONEY_ADJUST04 + TS.MONEY_FREIGHT04 - TD.MONEY_DEPOSIT_ADJ04) ADJUST4 ,SUM(TS.MONEY_ADJUST05 + TS.MONEY_FREIGHT05 - TD.MONEY_DEPOSIT_ADJ05) ADJUST5 ,SUM(TS.MONEY_ADJUST06 + TS.MONEY_FREIGHT06 - TD.MONEY_DEPOSIT_ADJ06) ADJUST6 ,SUM(TS.MONEY_ADJUST07 + TS.MONEY_FREIGHT07 - TD.MONEY_DEPOSIT_ADJ07) ADJUST7 ,SUM(TS.MONEY_ADJUST08 + TS.MONEY_FREIGHT08 - TD.MONEY_DEPOSIT_ADJ08) ADJUST8 ,SUM(TS.MONEY_ADJUST09 + TS.MONEY_FREIGHT09 - TD.MONEY_DEPOSIT_ADJ09) ADJUST9 ,SUM(TS.MONEY_ADJUST10 + TS.MONEY_FREIGHT10 - TD.MONEY_DEPOSIT_ADJ10) ADJUST10 ,SUM(TS.MONEY_ADJUST11 + TS.MONEY_FREIGHT11 - TD.MONEY_DEPOSIT_ADJ11) ADJUST11 ,SUM(TS.MONEY_ADJUST12 + TS.MONEY_FREIGHT12 - TD.MONEY_DEPOSIT_ADJ12) ADJUST12 ,SUM(TS.MONEY_ADJUST13 + TS.MONEY_FREIGHT13 - TD.MONEY_DEPOSIT_ADJ13) ADJUST13 ,SUM(TS.MONEY_ADJUST14 + TS.MONEY_FREIGHT14 - TD.MONEY_DEPOSIT_ADJ14) ADJUST14 ,SUM(TS.MONEY_ADJUST15 + TS.MONEY_FREIGHT15 - TD.MONEY_DEPOSIT_ADJ15) ADJUST15 ,SUM(TS.MONEY_ADJUST16 + TS.MONEY_FREIGHT16 - TD.MONEY_DEPOSIT_ADJ16) ADJUST16 ,SUM(TS.MONEY_ADJUST17 + TS.MONEY_FREIGHT17 - TD.MONEY_DEPOSIT_ADJ17) ADJUST17 ,SUM(TS.MONEY_ADJUST18 + TS.MONEY_FREIGHT18 - TD.MONEY_DEPOSIT_ADJ18) ADJUST18 ,SUM(TS.MONEY_ADJUST19 + TS.MONEY_FREIGHT19 - TD.MONEY_DEPOSIT_ADJ19) ADJUST19 ,SUM(TS.MONEY_ADJUST20 + TS.MONEY_FREIGHT20 - TD.MONEY_DEPOSIT_ADJ20) ADJUST20 ,SUM(TS.MONEY_ADJUST21 + TS.MONEY_FREIGHT21 - TD.MONEY_DEPOSIT_ADJ21) ADJUST21 ,SUM(TS.MONEY_ADJUST22 + TS.MONEY_FREIGHT22 - TD.MONEY_DEPOSIT_ADJ22) ADJUST22 ,SUM(TS.MONEY_ADJUST23 + TS.MONEY_FREIGHT23 - TD.MONEY_DEPOSIT_ADJ23) ADJUST23 ,SUM(TS.MONEY_ADJUST24 + TS.MONEY_FREIGHT24 - TD.MONEY_DEPOSIT_ADJ24) ADJUST24 ,SUM(TS.MONEY_ADJUST25 + TS.MONEY_FREIGHT25 - TD.MONEY_DEPOSIT_ADJ25) ADJUST25 ,SUM(TS.MONEY_ADJUST26 + TS.MONEY_FREIGHT26 - TD.MONEY_DEPOSIT_ADJ26) ADJUST26 ,SUM(TS.MONEY_ADJUST27 + TS.MONEY_FREIGHT27 - TD.MONEY_DEPOSIT_ADJ27) ADJUST27 ,SUM(TS.MONEY_ADJUST28 + TS.MONEY_FREIGHT28 - TD.MONEY_DEPOSIT_ADJ28) ADJUST28 ,SUM(TS.MONEY_ADJUST29 + TS.MONEY_FREIGHT29 - TD.MONEY_DEPOSIT_ADJ29) ADJUST29 ,SUM(TS.MONEY_ADJUST30 + TS.MONEY_FREIGHT30 - TD.MONEY_DEPOSIT_ADJ30) ADJUST30 ,SUM(TS.MONEY_ADJUST31 + TS.MONEY_FREIGHT31 - TD.MONEY_DEPOSIT_ADJ31) ADJUST31 -- 調整額は売上調整額と伝票の運賃と入金調整額とする。 -- 日別の伝票調整額 + 日別の運賃 - 日別の入金調整額 -- 前月21日〜末までの売上 ,SUM(TS_PRE.WEIGHT_SALE) WEIGHT_SALE_PRE ,SUM(TS_PRE.MONEY_SALE) MONEY_SALE_PRE ,SUM(TS_PRE.TAX) TAX_PRE ,(SUM(TS_PRE.MONEY_ADJUST) + SUM(TS_PRE.MONEY_FREIGHT) - SUM(TD_PRE.MONEY_DEPOSIT_ADJ)) ADJUST_PRE -- 前月21日〜末までの入金 ,SUM(TD_PRE.MONEY_DEPOSIT) MONEY_DEPOSIT_PRE FROM ( SELECT TS02.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,SUM(TS02.WEIGHT_SALE01) WEIGHT_SALE01 ,SUM(TS02.WEIGHT_SALE02) WEIGHT_SALE02 ,SUM(TS02.WEIGHT_SALE03) WEIGHT_SALE03 ,SUM(TS02.WEIGHT_SALE04) WEIGHT_SALE04 ,SUM(TS02.WEIGHT_SALE05) WEIGHT_SALE05 ,SUM(TS02.WEIGHT_SALE06) WEIGHT_SALE06 ,SUM(TS02.WEIGHT_SALE07) WEIGHT_SALE07 ,SUM(TS02.WEIGHT_SALE08) WEIGHT_SALE08 ,SUM(TS02.WEIGHT_SALE09) WEIGHT_SALE09 ,SUM(TS02.WEIGHT_SALE10) WEIGHT_SALE10 ,SUM(TS02.WEIGHT_SALE11) WEIGHT_SALE11 ,SUM(TS02.WEIGHT_SALE12) WEIGHT_SALE12 ,SUM(TS02.WEIGHT_SALE13) WEIGHT_SALE13 ,SUM(TS02.WEIGHT_SALE14) WEIGHT_SALE14 ,SUM(TS02.WEIGHT_SALE15) WEIGHT_SALE15 ,SUM(TS02.WEIGHT_SALE16) WEIGHT_SALE16 ,SUM(TS02.WEIGHT_SALE17) WEIGHT_SALE17 ,SUM(TS02.WEIGHT_SALE18) WEIGHT_SALE18 ,SUM(TS02.WEIGHT_SALE19) WEIGHT_SALE19 ,SUM(TS02.WEIGHT_SALE20) WEIGHT_SALE20 ,SUM(TS02.WEIGHT_SALE21) WEIGHT_SALE21 ,SUM(TS02.WEIGHT_SALE22) WEIGHT_SALE22 ,SUM(TS02.WEIGHT_SALE23) WEIGHT_SALE23 ,SUM(TS02.WEIGHT_SALE24) WEIGHT_SALE24 ,SUM(TS02.WEIGHT_SALE25) WEIGHT_SALE25 ,SUM(TS02.WEIGHT_SALE26) WEIGHT_SALE26 ,SUM(TS02.WEIGHT_SALE27) WEIGHT_SALE27 ,SUM(TS02.WEIGHT_SALE28) WEIGHT_SALE28 ,SUM(TS02.WEIGHT_SALE29) WEIGHT_SALE29 ,SUM(TS02.WEIGHT_SALE30) WEIGHT_SALE30 ,SUM(TS02.WEIGHT_SALE31) WEIGHT_SALE31 -- 日別の売上金額 ,SUM(TS02.MONEY_SALE01) MONEY_SALE01 ,SUM(TS02.MONEY_SALE02) MONEY_SALE02 ,SUM(TS02.MONEY_SALE03) MONEY_SALE03 ,SUM(TS02.MONEY_SALE04) MONEY_SALE04 ,SUM(TS02.MONEY_SALE05) MONEY_SALE05 ,SUM(TS02.MONEY_SALE06) MONEY_SALE06 ,SUM(TS02.MONEY_SALE07) MONEY_SALE07 ,SUM(TS02.MONEY_SALE08) MONEY_SALE08 ,SUM(TS02.MONEY_SALE09) MONEY_SALE09 ,SUM(TS02.MONEY_SALE10) MONEY_SALE10 ,SUM(TS02.MONEY_SALE11) MONEY_SALE11 ,SUM(TS02.MONEY_SALE12) MONEY_SALE12 ,SUM(TS02.MONEY_SALE13) MONEY_SALE13 ,SUM(TS02.MONEY_SALE14) MONEY_SALE14 ,SUM(TS02.MONEY_SALE15) MONEY_SALE15 ,SUM(TS02.MONEY_SALE16) MONEY_SALE16 ,SUM(TS02.MONEY_SALE17) MONEY_SALE17 ,SUM(TS02.MONEY_SALE18) MONEY_SALE18 ,SUM(TS02.MONEY_SALE19) MONEY_SALE19 ,SUM(TS02.MONEY_SALE20) MONEY_SALE20 ,SUM(TS02.MONEY_SALE21) MONEY_SALE21 ,SUM(TS02.MONEY_SALE22) MONEY_SALE22 ,SUM(TS02.MONEY_SALE23) MONEY_SALE23 ,SUM(TS02.MONEY_SALE24) MONEY_SALE24 ,SUM(TS02.MONEY_SALE25) MONEY_SALE25 ,SUM(TS02.MONEY_SALE26) MONEY_SALE26 ,SUM(TS02.MONEY_SALE27) MONEY_SALE27 ,SUM(TS02.MONEY_SALE28) MONEY_SALE28 ,SUM(TS02.MONEY_SALE29) MONEY_SALE29 ,SUM(TS02.MONEY_SALE30) MONEY_SALE30 ,SUM(TS02.MONEY_SALE31) MONEY_SALE31 -- 日別の消費税 ,SUM(TS02.TAX01) TAX01 ,SUM(TS02.TAX02) TAX02 ,SUM(TS02.TAX03) TAX03 ,SUM(TS02.TAX04) TAX04 ,SUM(TS02.TAX05) TAX05 ,SUM(TS02.TAX06) TAX06 ,SUM(TS02.TAX07) TAX07 ,SUM(TS02.TAX08) TAX08 ,SUM(TS02.TAX09) TAX09 ,SUM(TS02.TAX10) TAX10 ,SUM(TS02.TAX11) TAX11 ,SUM(TS02.TAX12) TAX12 ,SUM(TS02.TAX13) TAX13 ,SUM(TS02.TAX14) TAX14 ,SUM(TS02.TAX15) TAX15 ,SUM(TS02.TAX16) TAX16 ,SUM(TS02.TAX17) TAX17 ,SUM(TS02.TAX18) TAX18 ,SUM(TS02.TAX19) TAX19 ,SUM(TS02.TAX20) TAX20 ,SUM(TS02.TAX21) TAX21 ,SUM(TS02.TAX22) TAX22 ,SUM(TS02.TAX23) TAX23 ,SUM(TS02.TAX24) TAX24 ,SUM(TS02.TAX25) TAX25 ,SUM(TS02.TAX26) TAX26 ,SUM(TS02.TAX27) TAX27 ,SUM(TS02.TAX28) TAX28 ,SUM(TS02.TAX29) TAX29 ,SUM(TS02.TAX30) TAX30 ,SUM(TS02.TAX31) TAX31 -- 日別の伝票調整額 ,SUM(TS02.MONEY_ADJUST01) MONEY_ADJUST01 ,SUM(TS02.MONEY_ADJUST02) MONEY_ADJUST02 ,SUM(TS02.MONEY_ADJUST03) MONEY_ADJUST03 ,SUM(TS02.MONEY_ADJUST04) MONEY_ADJUST04 ,SUM(TS02.MONEY_ADJUST05) MONEY_ADJUST05 ,SUM(TS02.MONEY_ADJUST06) MONEY_ADJUST06 ,SUM(TS02.MONEY_ADJUST07) MONEY_ADJUST07 ,SUM(TS02.MONEY_ADJUST08) MONEY_ADJUST08 ,SUM(TS02.MONEY_ADJUST09) MONEY_ADJUST09 ,SUM(TS02.MONEY_ADJUST10) MONEY_ADJUST10 ,SUM(TS02.MONEY_ADJUST11) MONEY_ADJUST11 ,SUM(TS02.MONEY_ADJUST12) MONEY_ADJUST12 ,SUM(TS02.MONEY_ADJUST13) MONEY_ADJUST13 ,SUM(TS02.MONEY_ADJUST14) MONEY_ADJUST14 ,SUM(TS02.MONEY_ADJUST15) MONEY_ADJUST15 ,SUM(TS02.MONEY_ADJUST16) MONEY_ADJUST16 ,SUM(TS02.MONEY_ADJUST17) MONEY_ADJUST17 ,SUM(TS02.MONEY_ADJUST18) MONEY_ADJUST18 ,SUM(TS02.MONEY_ADJUST19) MONEY_ADJUST19 ,SUM(TS02.MONEY_ADJUST20) MONEY_ADJUST20 ,SUM(TS02.MONEY_ADJUST21) MONEY_ADJUST21 ,SUM(TS02.MONEY_ADJUST22) MONEY_ADJUST22 ,SUM(TS02.MONEY_ADJUST23) MONEY_ADJUST23 ,SUM(TS02.MONEY_ADJUST24) MONEY_ADJUST24 ,SUM(TS02.MONEY_ADJUST25) MONEY_ADJUST25 ,SUM(TS02.MONEY_ADJUST26) MONEY_ADJUST26 ,SUM(TS02.MONEY_ADJUST27) MONEY_ADJUST27 ,SUM(TS02.MONEY_ADJUST28) MONEY_ADJUST28 ,SUM(TS02.MONEY_ADJUST29) MONEY_ADJUST29 ,SUM(TS02.MONEY_ADJUST30) MONEY_ADJUST30 ,SUM(TS02.MONEY_ADJUST31) MONEY_ADJUST31 -- 日別の運賃 ,SUM(TS02.MONEY_FREIGHT01) MONEY_FREIGHT01 ,SUM(TS02.MONEY_FREIGHT02) MONEY_FREIGHT02 ,SUM(TS02.MONEY_FREIGHT03) MONEY_FREIGHT03 ,SUM(TS02.MONEY_FREIGHT04) MONEY_FREIGHT04 ,SUM(TS02.MONEY_FREIGHT05) MONEY_FREIGHT05 ,SUM(TS02.MONEY_FREIGHT06) MONEY_FREIGHT06 ,SUM(TS02.MONEY_FREIGHT07) MONEY_FREIGHT07 ,SUM(TS02.MONEY_FREIGHT08) MONEY_FREIGHT08 ,SUM(TS02.MONEY_FREIGHT09) MONEY_FREIGHT09 ,SUM(TS02.MONEY_FREIGHT10) MONEY_FREIGHT10 ,SUM(TS02.MONEY_FREIGHT11) MONEY_FREIGHT11 ,SUM(TS02.MONEY_FREIGHT12) MONEY_FREIGHT12 ,SUM(TS02.MONEY_FREIGHT13) MONEY_FREIGHT13 ,SUM(TS02.MONEY_FREIGHT14) MONEY_FREIGHT14 ,SUM(TS02.MONEY_FREIGHT15) MONEY_FREIGHT15 ,SUM(TS02.MONEY_FREIGHT16) MONEY_FREIGHT16 ,SUM(TS02.MONEY_FREIGHT17) MONEY_FREIGHT17 ,SUM(TS02.MONEY_FREIGHT18) MONEY_FREIGHT18 ,SUM(TS02.MONEY_FREIGHT19) MONEY_FREIGHT19 ,SUM(TS02.MONEY_FREIGHT20) MONEY_FREIGHT20 ,SUM(TS02.MONEY_FREIGHT21) MONEY_FREIGHT21 ,SUM(TS02.MONEY_FREIGHT22) MONEY_FREIGHT22 ,SUM(TS02.MONEY_FREIGHT23) MONEY_FREIGHT23 ,SUM(TS02.MONEY_FREIGHT24) MONEY_FREIGHT24 ,SUM(TS02.MONEY_FREIGHT25) MONEY_FREIGHT25 ,SUM(TS02.MONEY_FREIGHT26) MONEY_FREIGHT26 ,SUM(TS02.MONEY_FREIGHT27) MONEY_FREIGHT27 ,SUM(TS02.MONEY_FREIGHT28) MONEY_FREIGHT28 ,SUM(TS02.MONEY_FREIGHT29) MONEY_FREIGHT29 ,SUM(TS02.MONEY_FREIGHT30) MONEY_FREIGHT30 ,SUM(TS02.MONEY_FREIGHT31) MONEY_FREIGHT31 FROM (-- 得意先別納品先ごとのデータ SELECT TS01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の売上データ -- 日別の数量 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.WEIGHT_SALE ELSE 0 END WEIGHT_SALE31 -- 日別の売上金額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_SALE ELSE 0 END MONEY_SALE31 -- 日別の消費税 ,CASE WHEN TS01.DTS_DAY = 01 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX01 ,CASE WHEN TS01.DTS_DAY = 02 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX02 ,CASE WHEN TS01.DTS_DAY = 03 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX03 ,CASE WHEN TS01.DTS_DAY = 04 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX04 ,CASE WHEN TS01.DTS_DAY = 05 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX05 ,CASE WHEN TS01.DTS_DAY = 06 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX06 ,CASE WHEN TS01.DTS_DAY = 07 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX07 ,CASE WHEN TS01.DTS_DAY = 08 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX08 ,CASE WHEN TS01.DTS_DAY = 09 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX09 ,CASE WHEN TS01.DTS_DAY = 10 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX10 ,CASE WHEN TS01.DTS_DAY = 11 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX11 ,CASE WHEN TS01.DTS_DAY = 12 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX12 ,CASE WHEN TS01.DTS_DAY = 13 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX13 ,CASE WHEN TS01.DTS_DAY = 14 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX14 ,CASE WHEN TS01.DTS_DAY = 15 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX15 ,CASE WHEN TS01.DTS_DAY = 16 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX16 ,CASE WHEN TS01.DTS_DAY = 17 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX17 ,CASE WHEN TS01.DTS_DAY = 18 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX18 ,CASE WHEN TS01.DTS_DAY = 19 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX19 ,CASE WHEN TS01.DTS_DAY = 20 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX20 ,CASE WHEN TS01.DTS_DAY = 21 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX21 ,CASE WHEN TS01.DTS_DAY = 22 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX22 ,CASE WHEN TS01.DTS_DAY = 23 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX23 ,CASE WHEN TS01.DTS_DAY = 24 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX24 ,CASE WHEN TS01.DTS_DAY = 25 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX25 ,CASE WHEN TS01.DTS_DAY = 26 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX26 ,CASE WHEN TS01.DTS_DAY = 27 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX27 ,CASE WHEN TS01.DTS_DAY = 28 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX28 ,CASE WHEN TS01.DTS_DAY = 29 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX29 ,CASE WHEN TS01.DTS_DAY = 30 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX30 ,CASE WHEN TS01.DTS_DAY = 31 THEN (case(TS01.CD_CUSTOMER) when(1) then(trunc(TS01.MONEY_SALE * (TS01.RATE_TAX / 100))) else (TS01.TAX) end) ELSE 0 END TAX31 -- 日別の伝票調整額 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_ADJUST ELSE 0 END MONEY_ADJUST31 -- 日別の運賃 ,CASE WHEN TS01.DTS_DAY = 01 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT01 ,CASE WHEN TS01.DTS_DAY = 02 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT02 ,CASE WHEN TS01.DTS_DAY = 03 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT03 ,CASE WHEN TS01.DTS_DAY = 04 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT04 ,CASE WHEN TS01.DTS_DAY = 05 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT05 ,CASE WHEN TS01.DTS_DAY = 06 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT06 ,CASE WHEN TS01.DTS_DAY = 07 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT07 ,CASE WHEN TS01.DTS_DAY = 08 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT08 ,CASE WHEN TS01.DTS_DAY = 09 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT09 ,CASE WHEN TS01.DTS_DAY = 10 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT10 ,CASE WHEN TS01.DTS_DAY = 11 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT11 ,CASE WHEN TS01.DTS_DAY = 12 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT12 ,CASE WHEN TS01.DTS_DAY = 13 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT13 ,CASE WHEN TS01.DTS_DAY = 14 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT14 ,CASE WHEN TS01.DTS_DAY = 15 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT15 ,CASE WHEN TS01.DTS_DAY = 16 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT16 ,CASE WHEN TS01.DTS_DAY = 17 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT17 ,CASE WHEN TS01.DTS_DAY = 18 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT18 ,CASE WHEN TS01.DTS_DAY = 19 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT19 ,CASE WHEN TS01.DTS_DAY = 20 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT20 ,CASE WHEN TS01.DTS_DAY = 21 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT21 ,CASE WHEN TS01.DTS_DAY = 22 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT22 ,CASE WHEN TS01.DTS_DAY = 23 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT23 ,CASE WHEN TS01.DTS_DAY = 24 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT24 ,CASE WHEN TS01.DTS_DAY = 25 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT25 ,CASE WHEN TS01.DTS_DAY = 26 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT26 ,CASE WHEN TS01.DTS_DAY = 27 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT27 ,CASE WHEN TS01.DTS_DAY = 28 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT28 ,CASE WHEN TS01.DTS_DAY = 29 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT29 ,CASE WHEN TS01.DTS_DAY = 30 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT30 ,CASE WHEN TS01.DTS_DAY = 31 THEN TS01.MONEY_FREIGHT ELSE 0 END MONEY_FREIGHT31 FROM T_SALE TS01 WHERE (('&10'= '') OR (TS01.DTS_YEAR = ('&10' ::text) ::numeric)) AND (('&11'= '') OR (TS01.DTS_MONTH = ('&11' ::text) ::numeric)) AND TS01.FLG_DELETE = 0 and (('&1'= '') OR (TS01.CD_GREAD = ('&1' ::text) ::numeric)) ) TS02 GROUP BY TS02.CD_CUSTOMER ) ts, m_customer mc LEFT OUTER JOIN ( SELECT TD02.CD_CUSTOMER CD_CUSTOMER ,SUM(TD02.MONEY_DEPOSIT01) MONEY_DEPOSIT01 ,SUM(TD02.MONEY_DEPOSIT02) MONEY_DEPOSIT02 ,SUM(TD02.MONEY_DEPOSIT03) MONEY_DEPOSIT03 ,SUM(TD02.MONEY_DEPOSIT04) MONEY_DEPOSIT04 ,SUM(TD02.MONEY_DEPOSIT05) MONEY_DEPOSIT05 ,SUM(TD02.MONEY_DEPOSIT06) MONEY_DEPOSIT06 ,SUM(TD02.MONEY_DEPOSIT07) MONEY_DEPOSIT07 ,SUM(TD02.MONEY_DEPOSIT08) MONEY_DEPOSIT08 ,SUM(TD02.MONEY_DEPOSIT09) MONEY_DEPOSIT09 ,SUM(TD02.MONEY_DEPOSIT10) MONEY_DEPOSIT10 ,SUM(TD02.MONEY_DEPOSIT11) MONEY_DEPOSIT11 ,SUM(TD02.MONEY_DEPOSIT12) MONEY_DEPOSIT12 ,SUM(TD02.MONEY_DEPOSIT13) MONEY_DEPOSIT13 ,SUM(TD02.MONEY_DEPOSIT14) MONEY_DEPOSIT14 ,SUM(TD02.MONEY_DEPOSIT15) MONEY_DEPOSIT15 ,SUM(TD02.MONEY_DEPOSIT16) MONEY_DEPOSIT16 ,SUM(TD02.MONEY_DEPOSIT17) MONEY_DEPOSIT17 ,SUM(TD02.MONEY_DEPOSIT18) MONEY_DEPOSIT18 ,SUM(TD02.MONEY_DEPOSIT19) MONEY_DEPOSIT19 ,SUM(TD02.MONEY_DEPOSIT20) MONEY_DEPOSIT20 ,SUM(TD02.MONEY_DEPOSIT21) MONEY_DEPOSIT21 ,SUM(TD02.MONEY_DEPOSIT22) MONEY_DEPOSIT22 ,SUM(TD02.MONEY_DEPOSIT23) MONEY_DEPOSIT23 ,SUM(TD02.MONEY_DEPOSIT24) MONEY_DEPOSIT24 ,SUM(TD02.MONEY_DEPOSIT25) MONEY_DEPOSIT25 ,SUM(TD02.MONEY_DEPOSIT26) MONEY_DEPOSIT26 ,SUM(TD02.MONEY_DEPOSIT27) MONEY_DEPOSIT27 ,SUM(TD02.MONEY_DEPOSIT28) MONEY_DEPOSIT28 ,SUM(TD02.MONEY_DEPOSIT29) MONEY_DEPOSIT29 ,SUM(TD02.MONEY_DEPOSIT30) MONEY_DEPOSIT30 ,SUM(TD02.MONEY_DEPOSIT31) MONEY_DEPOSIT31 -- 日別の売上調整額 ,SUM(TD02.MONEY_DEPOSIT_ADJ01) MONEY_DEPOSIT_ADJ01 ,SUM(TD02.MONEY_DEPOSIT_ADJ02) MONEY_DEPOSIT_ADJ02 ,SUM(TD02.MONEY_DEPOSIT_ADJ03) MONEY_DEPOSIT_ADJ03 ,SUM(TD02.MONEY_DEPOSIT_ADJ04) MONEY_DEPOSIT_ADJ04 ,SUM(TD02.MONEY_DEPOSIT_ADJ05) MONEY_DEPOSIT_ADJ05 ,SUM(TD02.MONEY_DEPOSIT_ADJ06) MONEY_DEPOSIT_ADJ06 ,SUM(TD02.MONEY_DEPOSIT_ADJ07) MONEY_DEPOSIT_ADJ07 ,SUM(TD02.MONEY_DEPOSIT_ADJ08) MONEY_DEPOSIT_ADJ08 ,SUM(TD02.MONEY_DEPOSIT_ADJ09) MONEY_DEPOSIT_ADJ09 ,SUM(TD02.MONEY_DEPOSIT_ADJ10) MONEY_DEPOSIT_ADJ10 ,SUM(TD02.MONEY_DEPOSIT_ADJ11) MONEY_DEPOSIT_ADJ11 ,SUM(TD02.MONEY_DEPOSIT_ADJ12) MONEY_DEPOSIT_ADJ12 ,SUM(TD02.MONEY_DEPOSIT_ADJ13) MONEY_DEPOSIT_ADJ13 ,SUM(TD02.MONEY_DEPOSIT_ADJ14) MONEY_DEPOSIT_ADJ14 ,SUM(TD02.MONEY_DEPOSIT_ADJ15) MONEY_DEPOSIT_ADJ15 ,SUM(TD02.MONEY_DEPOSIT_ADJ16) MONEY_DEPOSIT_ADJ16 ,SUM(TD02.MONEY_DEPOSIT_ADJ17) MONEY_DEPOSIT_ADJ17 ,SUM(TD02.MONEY_DEPOSIT_ADJ18) MONEY_DEPOSIT_ADJ18 ,SUM(TD02.MONEY_DEPOSIT_ADJ19) MONEY_DEPOSIT_ADJ19 ,SUM(TD02.MONEY_DEPOSIT_ADJ20) MONEY_DEPOSIT_ADJ20 ,SUM(TD02.MONEY_DEPOSIT_ADJ21) MONEY_DEPOSIT_ADJ21 ,SUM(TD02.MONEY_DEPOSIT_ADJ22) MONEY_DEPOSIT_ADJ22 ,SUM(TD02.MONEY_DEPOSIT_ADJ23) MONEY_DEPOSIT_ADJ23 ,SUM(TD02.MONEY_DEPOSIT_ADJ24) MONEY_DEPOSIT_ADJ24 ,SUM(TD02.MONEY_DEPOSIT_ADJ25) MONEY_DEPOSIT_ADJ25 ,SUM(TD02.MONEY_DEPOSIT_ADJ26) MONEY_DEPOSIT_ADJ26 ,SUM(TD02.MONEY_DEPOSIT_ADJ27) MONEY_DEPOSIT_ADJ27 ,SUM(TD02.MONEY_DEPOSIT_ADJ28) MONEY_DEPOSIT_ADJ28 ,SUM(TD02.MONEY_DEPOSIT_ADJ29) MONEY_DEPOSIT_ADJ29 ,SUM(TD02.MONEY_DEPOSIT_ADJ30) MONEY_DEPOSIT_ADJ30 ,SUM(TD02.MONEY_DEPOSIT_ADJ31) MONEY_DEPOSIT_ADJ31 FROM ( SELECT TD01.CD_CUSTOMER CD_CUSTOMER -- 得意先別納品先別の入金データ -- 日別の売上入金 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 0 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT31 -- 日別の売上調整額 ,CASE WHEN TD01.DTS_DAY = 01 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ01 ,CASE WHEN TD01.DTS_DAY = 02 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ02 ,CASE WHEN TD01.DTS_DAY = 03 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ03 ,CASE WHEN TD01.DTS_DAY = 04 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ04 ,CASE WHEN TD01.DTS_DAY = 05 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ05 ,CASE WHEN TD01.DTS_DAY = 06 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ06 ,CASE WHEN TD01.DTS_DAY = 07 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ07 ,CASE WHEN TD01.DTS_DAY = 08 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ08 ,CASE WHEN TD01.DTS_DAY = 09 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ09 ,CASE WHEN TD01.DTS_DAY = 10 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ10 ,CASE WHEN TD01.DTS_DAY = 11 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ11 ,CASE WHEN TD01.DTS_DAY = 12 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ12 ,CASE WHEN TD01.DTS_DAY = 13 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ13 ,CASE WHEN TD01.DTS_DAY = 14 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ14 ,CASE WHEN TD01.DTS_DAY = 15 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ15 ,CASE WHEN TD01.DTS_DAY = 16 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ16 ,CASE WHEN TD01.DTS_DAY = 17 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ17 ,CASE WHEN TD01.DTS_DAY = 18 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ18 ,CASE WHEN TD01.DTS_DAY = 19 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ19 ,CASE WHEN TD01.DTS_DAY = 20 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ20 ,CASE WHEN TD01.DTS_DAY = 21 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ21 ,CASE WHEN TD01.DTS_DAY = 22 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ22 ,CASE WHEN TD01.DTS_DAY = 23 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ23 ,CASE WHEN TD01.DTS_DAY = 24 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ24 ,CASE WHEN TD01.DTS_DAY = 25 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ25 ,CASE WHEN TD01.DTS_DAY = 26 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ26 ,CASE WHEN TD01.DTS_DAY = 27 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ27 ,CASE WHEN TD01.DTS_DAY = 28 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ28 ,CASE WHEN TD01.DTS_DAY = 29 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ29 ,CASE WHEN TD01.DTS_DAY = 30 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ30 ,CASE WHEN TD01.DTS_DAY = 31 THEN CASE WHEN TD01.DIV_DEPOSIT = 1 THEN TD01.MONEY_DEPOSIT ELSE 0 END ELSE 0 END MONEY_DEPOSIT_ADJ31 FROM T_DEPOSIT TD01 WHERE (('&10'= '') OR (TD01.DTS_YEAR = ('&10' ::text) ::numeric)) AND (('&11'= '') OR (TD01.DTS_MONTH = ('&11' ::text) ::numeric)) AND TD01.DIV_DELETE = 0 ) TD02 GROUP BY TD02.CD_CUSTOMER ) td ON (MC.CD_CUSTOMER = TD.CD_CUSTOMER) LEFT OUTER JOIN (-- 得意先ごとのデータ SELECT CD_CUSTOMER -- 得意先別の売上データ -- 日別の数量 ,SUM(WEIGHT_SALE) WEIGHT_SALE -- 日別の売上金額 ,SUM(MONEY_SALE) MONEY_SALE -- 日別の消費税 ,SUM(TAX) TAX -- 日別の伝票調整額 ,SUM(MONEY_ADJUST) MONEY_ADJUST -- 日別の運賃 ,SUM(MONEY_FREIGHT) MONEY_FREIGHT FROM T_SALE WHERE (('&14'= '') OR (DTS_YEAR = ('&14' ::text) ::numeric)) AND (('&12'= '') OR (DTS_MONTH = ('&12' ::text) ::numeric)) AND DTS_DAY >= 21 AND DTS_DAY <= 31 AND FLG_DELETE = 0 and (('&1'= '') OR (CD_GREAD = ('&1' ::text) ::numeric)) GROUP BY CD_CUSTOMER ) ts_pre ON (MC.CD_CUSTOMER = TS_PRE.CD_CUSTOMER) LEFT OUTER JOIN ( SELECT CD_CUSTOMER -- 得意先別の入金データ -- 日別の売上入金 ,SUM(CASE WHEN DIV_DEPOSIT = 0 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT -- 日別の売上調整額 ,SUM(CASE WHEN DIV_DEPOSIT = 1 THEN MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT_ADJ FROM T_DEPOSIT WHERE (('&14'= '') OR (DTS_YEAR = ('&14' ::text) ::numeric)) AND (('&12'= '') OR (DTS_MONTH = ('&12' ::text) ::numeric)) AND DIV_DELETE = 0 AND DTS_DAY >= 21 AND DTS_DAY <= 31 GROUP BY CD_CUSTOMER ) td_pre ON (MC.CD_CUSTOMER = TD_PRE.CD_CUSTOMER) WHERE (('&4'= '') OR (MC.CD_CUSTOMER >= ('&4' ::text) ::numeric)) AND (('&5'= '') OR (MC.CD_CUSTOMER <= ('&5' ::text) ::numeric)) AND MC.CD_CUSTOMER = TS.CD_CUSTOMER AND MC.DT_START = ( SELECT MAX(MC01.DT_START) FROM M_CUSTOMER MC01 WHERE MC01.CD_CUSTOMER = MC.CD_CUSTOMER) GROUP BY MC.CD_CUSTOMER, MC.NAME_CUSTOMER ORDER BY MC.CD_CUSTOMER, MC.NAME_CUSTOMER --************************************************************************** --* 前月までの差引残高を取得 --*  --************************************************************************** [lselectRecords25] SELECT PF.CD_CUSTOMER ,SUM(PF.WEIGHT_SALE) WEIGHT_SALE ,SUM(PF.MONEY_SALE) MONEY_SALE ,SUM(PF.TAX) TAX ,SUM(PF.MONEY_ADJUST) MONEY_ADJUST ,SUM(PF.MONEY_FREIGHT) MONEY_FREIGHT ,SUM(PF.MONEY_DEPOSIT) MONEY_DEPOSIT ,SUM(PF.MONEY_ADJUST + PF.MONEY_FREIGHT - PF.MONEY_DEPOSIT_ADJUST) MONEY_DEPOSIT_ADJUST FROM( select TS.CD_CUSTOMER ,sum(TS.UNIT_PRICE_SALE) UNIT_PRICE_SALE ,sum(TS.WEIGHT_SALE) WEIGHT_SALE ,sum(TS.MONEY_SALE) MONEY_SALE ,sum(TS.TAX) TAX ,coalesce(SUM(TS.MONEY_ADJUST), 0) MONEY_ADJUST ,coalesce(sum(TS.MONEY_FREIGHT), 0) MONEY_FREIGHT ,0 MONEY_DEPOSIT ,0 MONEY_DEPOSIT_ADJUST from T_SALE TS where (TO_CHAR(TS.DT_SALE, 'YYYYMM') ::text) ::numeric <= ('&14' || '&12' ::text) ::numeric and TS.FLG_DELETE = 0 and (('' = '') OR (TS.CD_CUSTOMER = ('' ::text) ::numeric)) and (('&1' = '') OR (TS.CD_GREAD = ('&1' ::text) ::numeric)) GROUP BY TS.CD_CUSTOMER UNION select TD.CD_CUSTOMER ,0 UNIT_PRICE_SALE ,0 WEIGHT_SALE ,0 MONEY_SALE ,0 TAX ,0 MONEY_ADJUST ,0 MONEY_FREIGHT ,SUM(CASE WHEN TD.DIV_DEPOSIT = 0 THEN TD.MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT ,SUM(CASE WHEN TD.DIV_DEPOSIT = 1 THEN TD.MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT_ADJST FROM T_DEPOSIT TD WHERE (TO_CHAR(TD.DT_DEPOSIT, 'YYYYMM') ::text) ::numeric <= ('&14' || '&12' ::text) ::numeric and (('' = '') OR (TD.CD_CUSTOMER = ('' ::text) ::numeric)) AND DIV_DELETE = 0 GROUP BY TD.CD_CUSTOMER ) PF GROUP BY PF.CD_CUSTOMER --************************************************************************** --* 前月までの差引残高を取得 --*  --************************************************************************** [lselectRecords26] SELECT PF.CD_CUSTOMER ,SUM(PF.WEIGHT_SALE) WEIGHT_SALE ,SUM(PF.MONEY_SALE) MONEY_SALE ,SUM(PF.TAX) TAX ,SUM(PF.MONEY_ADJUST) MONEY_ADJUST ,SUM(PF.MONEY_FREIGHT) MONEY_FREIGHT ,SUM(PF.MONEY_DEPOSIT) MONEY_DEPOSIT ,SUM(PF.MONEY_ADJUST + PF.MONEY_FREIGHT - PF.MONEY_DEPOSIT_ADJUST) MONEY_DEPOSIT_ADJUST FROM( select TS.CD_CUSTOMER ,sum(TS.UNIT_PRICE_SALE) UNIT_PRICE_SALE ,sum(TS.WEIGHT_SALE) WEIGHT_SALE ,sum(TS.MONEY_SALE) MONEY_SALE ,sum(TS.TAX) TAX ,coalesce(SUM(TS.MONEY_ADJUST), 0) MONEY_ADJUST ,coalesce(sum(TS.MONEY_FREIGHT), 0) MONEY_FREIGHT ,0 MONEY_DEPOSIT ,0 MONEY_DEPOSIT_ADJUST from T_SALE TS where (TO_CHAR(TS.DT_SALE, 'YYYYMM') ::text) ::numeric <= ('&14' || '&12' ::text) ::numeric and TS.FLG_DELETE = 0 and (('' = '') OR (TS.CD_CUSTOMER = ('' ::text) ::numeric)) and (('&1' = '') OR (TS.CD_GREAD = ('&1' ::text) ::numeric)) GROUP BY TS.CD_CUSTOMER UNION select TD.CD_CUSTOMER ,0 UNIT_PRICE_SALE ,0 WEIGHT_SALE ,0 MONEY_SALE ,0 TAX ,0 MONEY_ADJUST ,0 MONEY_FREIGHT ,SUM(CASE WHEN TD.DIV_DEPOSIT = 0 THEN TD.MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT ,SUM(CASE WHEN TD.DIV_DEPOSIT = 1 THEN TD.MONEY_DEPOSIT ELSE 0 END) MONEY_DEPOSIT_ADJST FROM T_DEPOSIT TD WHERE (TO_CHAR(TD.DT_DEPOSIT, 'YYYYMM') ::text) ::numeric <= ('&14' || '&12' ::text) ::numeric and (('' = '') OR (TD.CD_CUSTOMER = ('' ::text) ::numeric)) AND DIV_DELETE = 0 GROUP BY TD.CD_CUSTOMER ) PF GROUP BY PF.CD_CUSTOMER