Pivot on datetime with matching multiple column

datetimepivot

I have the following table with column school, state, subject and timedate.
enter image description here

I would like to have output with column school, state, act and english

  • filter subjects to only Act and English
  • pivot table to match school and state

enter image description here

I did tried but all queries are not work. Hopefully someone may help. Thanks.

Best Answer

Quickly:

select school, state, Act, English, History
from (select school, state, subject, timedate
      from data) as pivotdata
         pivot (max(timedate) for subject in (Act, English, History)) as P

Should work

enter image description here

Related Question