sql server - SQL selecting with multiple joins -
i have example of database 3 tables.
1 work: workid, stateid, createddate 2 work history table: workid, old_state, new_state, transitiondate 3 work state: stateid; statename let's possible states 1 = ready, 2 = test , 3 = approved
i want make query print list works , of state changes. results should this:
id, createddate, currentstate, oldstate, newstate, transitiondate 1, 1-1-2016, approved, ready, test, 1-1-2016 1, 1-1-2016, approved, test, approved, 2-1-2016 2, 1-5-2016, test, ready, test, 1-5-2016 3, 1-10-2016, approved, ready, test, 1-10-2016 3, 1-10-2016, approved, test, approved, 1-15-2016 ... i know how make inner join can name of current state of work state table, can't names of old , new state. sort of join commands should use?
please use below query -
select t1.workid , t1.createddate , t3.statename currentstate , t4.statename oldstate , t5.statename newstate, t2.transitiondate [work] t1 join [work history] t2 on t1.workid = t2.workid join [state] t3 on t3.stateid = t1.stateid join [state] t4 on t4.stateid = t2.old_state join [state] t5 on t5.stateid = t2.new_state
Comments
Post a Comment