How to join 2 queries in SQL Server with value after sum -
i want join 2 queries after sum column num_tm....
select con_no, exp_dt, nte_dr, dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'bl') , dkd_id = 'bl' union select con_no, exp_dt, nte_dr, dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'dc') , dkd_id = 'dc' union select con_no, exp_dt, nte_dr, dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'tu' ) , dkd_id = 'tu'
select dkd_id, sum(amt_qt) amt_qt filb01b dkd_id ='bl' group dkd_id union select dkd_id, sum(amt_qt) amt_qt filb01b dkd_id ='dc' group dkd_id union select dkd_id, sum(amt_qt) amt_qt filb01b dkd_id = 'tu' group dkd_id
you mean this?
select * ( select con_no,exp_dt,nte_dr,dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'bl') , dkd_id = 'bl' union select con_no,exp_dt,nte_dr,dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'dc') , dkd_id = 'dc' union select con_no,exp_dt,nte_dr,dkd_id filb01b num_tm = (select max(num_tm) filb01b dkd_id = 'tu' ) , dkd_id = 'tu' ) inner join ( select * ( select dkd_id,sum(amt_qt) amt_qt filb01b dkd_id ='bl' group dkd_id union select dkd_id,sum(amt_qt)as amt_qt filb01b dkd_id ='dc' group dkd_id union select dkd_id,sum(amt_qt)as amt_qt filb01b dkd_id ='tu' group dkd_id ) b ) b on a.yourkey = b.yourkey
Comments
Post a Comment