Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Voting/Ranking logic with SQL
- select
- a.id,
- (
- select
- min(c.id)
- from
- table1 c
- where
- c.id>a.id
- limit 1
- ) as id2
- from
- table1 a
- order by
- rand()
- limit 1;
- select
- b.id
- from
- table1 b,
- (
- select
- a.id as id
- from
- table1 a
- where
- a.id<(select max(id) from table1 limit 1)
- order by
- rand()
- limit 1
- ) a
- where
- b.id>=a.id
- order by
- b.id
- limit 2
- ;
- with first as (select id
- from table t
- where id < (select max(id) from table)
- order by rand()
- limit 1
- )
- select id
- from table t
- order by abs(id - first.id)
- limit 2
Advertisement
Add Comment
Please, Sign In to add comment