Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
564 B
1
Indexable
Never
	DROP TABLE IF EXISTS #vtt
	SELECT vt.client_inn, vt.contract_name, vt.region, 
	CAST(MAX(vt.datetime_trn)OVER(PARTITION BY vt.client_inn,vt.contract_name) AS DATE) AS MAX_DOC_date
	INTO #vtt
	FROM [DATAMARTS].[dpa].vw_transactions vt -- продажи конечных клиентов 
	--WHERE YEAR(vt.datetime_trn)=YEAR(dateadd(year, -1, getdate())) -- текущий год -1 UPD: за весь приод берем
	--AND agent_inn IN (@inn_1,@inn_2) 
	--AND sale_channel='НП'
	GROUP BY vt.datetime_trn, vt.client_inn, vt.contract_name, vt.region
Leave a Comment