Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular

SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code. You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.

Copy Format Clear
WITH t (hospital, city, region) AS ( SELECT 'ПУДП 3', 'Москва', 'Московский' FROM dual UNION ALL SELECT 'ЦКБ УДП', 'Москва', 'Московский' FROM dual UNION ALL SELECT 'Поликлиника №1', 'Ярославль', 'Ярославский' FROM dual ) SELECT CASE WHEN GROUPING_ID(region,hospital,city) = 3 THEN t.region ELSE t.hospital END hospital, t.city FROM t GROUP BY GROUPING SETS(t.region,(t.region,t.hospital,t.city)) ORDER BY t.region, GROUPING_ID(t.region,t.hospital,t.city) DESC, t.hospital, t.city

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear