Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +------+------+
- | id | res |
- +------+------+
- | 1 | 55 |
- | 2 | 10 |
- | 3 | 89 |
- | 4 | 100 |
- | 5 | 80 |
- | 6 | 55 |
- | 7 | 70 |
- | 8 | 35 |
- | 9 | 46 |
- | 10 | 51 |
- +------+------+
- +------+------+
- | id |count |
- +------+------+
- | 1 | 4 |
- | 2 | 0 |
- | 3 | 8 |
- | 4 | 9 |
- | 5 | 7 |
- | 6 | 4 |
- | 7 | 6 |
- | 8 | 1 |
- | 9 | 2 |
- | 10 | 3 |
- +------+------+
- select
- id,
- res,
- rank() over (ORDER BY res) as rank
- from
- my_table
- order by
- res
- +-----+------+
- | id | _c1 |
- +-----+------+
- | 1 | 4 |
- | 2 | 0 |
- | 3 | 8 |
- | 4 | 9 |
- | 5 | 7 |
- | 6 | 4 |
- | 7 | 6 |
- | 8 | 1 |
- | 9 | 2 |
- | 10 | 3 |
- +-----+------+
- SELECT id, SUM(IF ( c.res1 > c.res2, 1 , 0 ))
- FROM (
- SELECT id, a.res AS res1, b.res AS res2
- FROM test_4 AS a
- INNER JOIN (
- SELECT res
- FROM test_4
- ) b
- ) c
- GROUP BY id;
- select
- id,
- res,
- rank() over (ORDER BY res) -1 as rank
- FROM point
- ORDER BY id
- Select id, sum(comparison) as count
- From (
- Select
- a.id,
- a.res as res1,
- b.res as res2,
- Case when a.res > b.res then 1
- Else 0
- End as comparison
- FROM point a
- CROSS JOIN point b
- ) c
- GROUP BY id
- SELECT mt.id AS id
- , mt.res AS res
- , COUNT(1) OVER (PARTITION BY NULL ORDER BY mt.res ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) - 1 AS cnt
- FROM my_table mt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement