
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 0.73 KB | hits: 8 | expires: Never
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