天天看点

distinct的位置,开窗函数,限制小数点取值位数,not exists运用实例

select  distinct t.* from                                   --<---distinct的位置
	(select 
		a.fperiod
		,a.matnr
		,round((a.sum_cost/(count(1) over(partition by a.fperiod,a.matnr)* b.peinh)),15) as cost           --<---开窗函数,限制小数点取值位数
		,a.fperiod as dt_month
		from (
			select 
				fperiod						--年月
				,matnr						--物料
				,sum(cost) as sum_cost
			from 库名.表名
			where vprsv ='W' and bwkey !='1234'
			group by fperiod
					,matnr
		)a
		left join  dm.dm_modle_pvp b 
		on a.fperiod = b.fperiod
		and a.matnr = b.matnr
		where b.vprsv ='W'
		and not exists                                                --<---not exists运用
		(select 
			matnr 
			from 库名.表名 b
			where vprsv ='W'
			and bwkey ='1234'
			and a.matnr=b.matnr)) t
           

继续阅读