There is a table containing information about space objects, in particular, their type (for example, a star, a planet, etc.) and the date of their discovery (type DATETIME). It is necessary to write a query that would display the number of objects of each type that were open in each century. The output should look like this:

enter image description here

  • one
    GROUP BY object_type + PIVOT manually on CASE YEAR(discovery_date) MOD 100 . - Akina

1 answer 1

You can like this:

 SELECT COUNT(*) count, type_id, FLOOR(YEAR(found_at) / 100) centry FROM test GROUP BY type_id, FLOOR(YEAR(found_at) / 100); 

And laid out a solution here, so that it can be seen in action: You can see here

  • Duplicate the request text in the response itself, the response should be complete and not a link to a third-party resource - Bald
  • Duplicate better in response, otherwise it may get lost - DaemonHK
  • The author clearly states: The output should look like this . In this answer, the output looks different. - Akina