mysql - SQL query: Separate column where IDs are the same but type is different -
basically simple select query:
select site.refid, sitename, dates.date, dates.type site, dates site.refid = dates.refid; refid | sitename | date | type 1 sydney 06-12-15 opened 1 sydney 08-12-15 closed 2 mel 17-12-15 opened 2 mel 19-12-15 closed
but want seperate tge result similar this:
refid | sitename | dateopened | dateclosed 1 sydney 06-12-15 | 08-12-15
basically want compare data tracking details
apologies in advance if question isn't structured :/ i'm complete beginner
i thinking maybe select within select or possible case when's, can't seem either working
try following approach, using case
expression:
select s.refid , s.name , min(case when d.type == 'opened' d.date end) dateopened , min(case when d.type == 'closed' d.date end) dateclosed site s join dates d on s.refid = d.refid group s.refid, s.name
Comments
Post a Comment