SQL tutorial - row column transform
In this case, I intend to introduce a complicated SQL query problem: row column transform. In the last chapter, about the fundamental SQL syntax , I used a MySQL sample database named sakila . In this tutorial, I still use it. transform rows to columns Task #1: Take table actor inside sakila for example, How to query the most popular last_names? let limit the condition to the last_names repeat at least more than 3 times. USE sakila ; SELECT last_name , COUNT ( first_NAME ) as size FROM actor GROUP BY last_name having size > 3; We got the result: + -----------+------+ | last_name | size | + -----------+------+ | KILMER | 5 | | NOLTE | 4 | | TEMPLE | 4 | + -----------+------+ Task #2: Convert above result from row to column format. + --------+-------+--------+ | KILMER | NOLTE | TEMPLE | + --------+-------+--------+ | 5 | 4 | 4 | + --------+-------+--------+ Use CASE WHEN an...