Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- id | owner_id | type | name
- ----+----------+------+----------
- 1 | 1 | A | a item 1
- 2 | 1 | A | a item 2
- 3 | 1 | B | b item 1
- 4 | 1 | B | b item 2
- 5 | 1 | C | c item 1
- 6 | 1 | C | c item 2
- 7 | 1 | D | d item 1
- 8 | 2 | A | a item 3
- 9 | 2 | C | c item 3
- id | type | name
- ----+------+----------
- 3 | B | b item 1
- 4 | B | b item 2
- 5 | C | c item 1
- 6 | C | c item 2
- 1 | A | a item 1
- 2 | A | a item 2
- SELECT id,
- type,
- name
- FROM items
- WHERE owner_id = 1
- AND type IN ('A', 'B', 'C')
- ORDER BY type != 'B',
- type != 'C',
- type != 'A',
- name;
- dense_rank() OVER (PARTITION BY type)
Add Comment
Please, Sign In to add comment