首页 > 数据库 >oracle 分组 聚合数据 单字段聚合问题

oracle 分组 聚合数据 单字段聚合问题

时间:2022-09-02 17:25:38浏览次数:65  
标签:bd 聚合 stordoc max 单字 FINPRODIN oracle IC NCC10

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

标签:bd,聚合,stordoc,max,单字,FINPRODIN,oracle,IC,NCC10
From: https://www.cnblogs.com/fuqian/p/16650614.html

相关文章

  • sqlserver 分组 聚合数据
    SELECT--OrderNo数据分组条件OrderNo,LEFT(MAX(InDate),10)ASInDate,--MAX只是不想让它参与分组条件MAX(WarehouseCode)WarehouseCode,MAX(Warehous......
  • 查看Oracle当前用户下的(表,视图,同义词,索引等...)
     copy自:查看Oracle当前用户下的(表,视图,同义词,索引等...)表空间–查看当前用户表空间selectusername,default_tablespacefromuser_users;selectdefault_tablespace......
  • oracle创建序列
    1创建一个序列,这个是给userLoginlog表用的,所以起了个关联名createsequenceseq_on_userloginincrementby1startwith1nomaxvaluenocyclenocache;2插入数据......
  • cent7.3离线安装oracle19c
    需要准备的安装包下载oracle-database-ee-19c-1.0-1.x86_64.rpmoracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm下载依赖http://rpmfind.net/linux/rpm2html/sea......
  • Oracle数据库expdp用法
    copy自:Oracle数据库expdp用法以及注意事项一、导出注意事项检查数据库版本(用于决定导出时生成为哪个版本的dmp头文件)selectversionfromv$instance;也可以用sqlplus......
  • oracle查看归档信息
    1、查看归档信息showparameterrecovery_file_dest#查看归档目录showparameterrecovery_file_dest_size#查看归档可以存储的大小2、查看每天的归档文件数量s......
  • 设置VF聚合网口
    查看PCI网卡#lspci|grepEth19:00.0Ethernetcontroller:IntelCorporationEthernetControllerX710for10GbESFP+(rev02)19:00.1Ethernetcontroller:Int......
  • oracle同义词SYNONYM语法
    同义词从字面上理解就是别名的意思,和试图的功能类似。就是一种映射关系。 dba给用户授同义词权限grantcreatesynonymtouser_name 1.创建同义词语句:cre......
  • oracle游标CURSOR写法
    1.声明游标在DECLEAR部分按以下格式声明游标:CURSOR游标名[(参数1数据类型[,参数2数据类型...])]ISSELECT语句;参数是可选部分,所定义的参数可以出现在SELECT语句的WHE......
  • Oracle表空间,用户创建及授权
    第1步:创建临时表空间  createtemporarytablespaceyuhang_temptempfile'D:\oracledata\yuhang_temp.dbf'size50mautoextendonnext50mmaxsize20480m......