Module 4 ยท Dates, windows and time Lesson 12 of 15
Pivot a table in SQL with CASE
Not every database has PIVOT, but CASE works everywhere: turn one column of values into several columns of counts, the same shape a spreadsheet pivot gives you.
Worked example
SUM(CASE WHEN type = 'remote' THEN 1 ELSE 0 END) AS remote counts the remote rows as a column, and the same trick gives onsite and hybrid in one grouped query.
Your practice task
Write one query showing city as rows and remote, onsite and hybrid as columns, with a count in each cell.
Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.
Key takeaway
Not every database has PIVOT, but CASE works everywhere: turn one column of values into several columns of counts, the same shape a spreadsheet pivot gives you.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
Almost there
15 lessons left of 15
Finish every lesson to unlock the certificate. Each one ends in a practice task โ do them and the final project brief writes itself.