SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Hint: use Ctrl+Enter for SQL autocomplete CREATE TABLE tt (fd int, tp char(2), rs char(1)); INSERT INTO tt (fd, tp, rs) VALUES (1, 'a1', 's'), (1, 'a2', 'm'), (1, 'a3', 's'), (1, 'a1', 'd'), (2, 'a1', 's'), (2, 'a1', 'm'), (3, 'a1', 's'), (3, 'a2', 's'), (4, 'a1', 's'), (5, 'a1', 'm'), (6, 'a1', 'm'), (6, 'a2', 's'); select distinct on(fd) fd, rs from tt group by fd, rs order by fd, array_position(ARRAY['s','m','d']::char(1)[], rs) desc
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear