sql server 2008 - Writing SQL Query, Separating One Columns Into two columns with filter -
i not db administrator , facing problem querying single table.
i got table follow
updated
i wan make query come out following picture
updated
how can it? quite noob query thanks.
you can this:
select max(t1.closedate) [date], t1.job, max(case when t1.workrole = 'case' coalesce(t2.worktype,t1.worktype) end) [case], max(case when t1.workrole = 'engineer' coalesce(t1.worktype,t2.worktype) end) [wt] tablename t1 left join tablename t2 on t1.closedate<t2.closedate , t1.job=t2.job group t1.job order [date] desc
result:
date job case wt ------------------------------------------------------ january, 01 2008 00:00:00 senior normal electronic january, 01 2005 00:00:00 junior average electronic
sample result in sql fiddle.
Comments
Post a Comment