tab1
SELECT * FROM tab1
id
та name
з таблиці tab1
SELECT id, name FROM tab1
name
. Пряме сортування ASC, зворотнє DESCSELECT id, name FROM tab1 ORDER BY name ASC
id
та name
з фільтром по полю id
SELECT id, name FROM tab1 WHERE id > 1
id
та name
. Додатково обчислюється порядковий номер рядка з використанням віконних функцій. SELECT id, name, row_number() OVER (ORDER BY name) AS number FROM tab1 GROUP BY id, name
SELECT id, name, row_number() OVER (ORDER BY name) AS number FROM tab1 GROUP BY id, name HAVING id > 1
SELECT id, name FROM tab1 AS tab1_1 UNION ALL SELECT id, name FROM tab1 AS tab1_2
WITH S AS ( SELECT name, row_number() OVER (ORDER BY name) AS number FROM tab1 GROUP BY name ) SELECT * FROM S
WITH S AS ( SELECT name, row_number() OVER (ORDER BY name) AS num, 'Перша' AS Group FROM tab1 GROUP BY name ), S2 AS ( SELECT name, row_number() OVER (ORDER BY name), 'Друга' FROM tab1 GROUP BY name ) SELECT * FROM S UNION ALL SELECT * FROM S2
© accounting.org.ua - 2024