SQL Query가 모두에 맞게 동작시키는 것이 어렵네요..
MySQL 5.6, PostgreSQL9.6, MS SQL Server 2017..
(MySQL 8.0은 아직 없습니다.)
http://sqlfiddle.com/