Created
October 10, 2019 16:28
-
-
Save YarikST/3bd229189842dd53e4dc3326a6038cb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TEMP TABLE task | |
as | |
select * | |
from ( | |
VALUES | |
(1 :: int, 'Xліб' :: VARCHAR), | |
(2 :: int, 'Xліб' :: VARCHAR), | |
(3 :: int, 'Xліб' :: VARCHAR), | |
(4 :: int, 'Вино' :: VARCHAR), | |
(5 :: int, 'Вино' :: VARCHAR), | |
(6 :: int, 'Ноутбук' :: VARCHAR), | |
(7 :: int, 'Ноутбук' :: VARCHAR), | |
(8 :: int, 'Ноутбук' :: VARCHAR) | |
) as t (id, category_name); | |
select | |
task.*, | |
sort_catgory.sort_priority | |
from task | |
INNER JOIN (select x.* | |
from (VALUES ('Xліб', 2), ('Вино', 1)) x(category_name, sort_priority)) sort_catgory | |
on sort_catgory.category_name = task.category_name | |
order by sort_catgory.sort_priority asc | |
INNER JOIN or LEFT OUTER JOIN - аби фільтрувати лише | |
VALUES - можна динамічно генерити або якось придумати визначену структуру для запитів - тіпа - build json object | |
NETWORK | |
https://stackoverflow.com/questions/29775500/rails-order-on-columns-values-priority-column |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment