sql server - How to get the transaction data with Date from First transaction date and Address from latest transaction Date if updated? -
i trying rearrange data date first transaction/shopping date , address latest transaction. data consists of transaction of single customer on various dates. please help.
the desired out should like:
due lack of table structure etc., here "dummy" code. idea first evaluate min , max date each customer , perform join between corresponding records:
with cte as( select [customer code_transaction]) customercode ,min([invoice date_transaction]) mindate ,max([invoice date_transaction]) maxdate [yourtable...] group [customer code_transaction] ) select t1.[invoice date_transaction] ,t1.[customer code_transaction] ,t1.[customer name_transaction] ,t2.[address_custreport] [yourtable...] t1 join cte c on c.mindate = t1.[invoice date_transaction] , c.customercode = t1.[customer code_transaction] join [yourtable...] t2 on t2.[customer code_transaction] = c.[customer code_transaction] , t2.[invoice date_transaction] = c.maxdate 

Comments
Post a Comment