drop procedure if exists get_user_rating // create procedure get_user_rating ( in uid int unsigned) end // * This source code was highlighted with Source Code Highlighter .
drop procedure if exists get_user_rating // create procedure get_user_rating ( in uid int unsigned) end // * This source code was highlighted with Source Code Highlighter .
drop procedure if exists get_user_rating // create procedure get_user_rating ( in uid int unsigned) end // * This source code was highlighted with Source Code Highlighter .
drop procedure if exists get_user_rating // create procedure get_user_rating ( in uid int unsigned) end // * This source code was highlighted with Source Code Highlighter .
drop procedure if exists get_user_rating // create procedure get_user_rating ( in uid int unsigned) end // * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- drop procedure if exists get_user_rating //
- create procedure get_user_rating ( in uid int unsigned)
- begin
- drop table if exists rating_tmp;
- create temporary table rating_tmp (
- `points` int unsigned,
- ` time` int unsigned,
- `uid` int unsigned,
- `answered int unsigned
- );
- end //
* This source code was highlighted with Source Code Highlighter .
- select @points: = points from rating r where r.uid = uid;
* This source code was highlighted with Source Code Highlighter .
- select h.points, h. time , h.uid, h.answered
- from rating h
- where @points <h.points
- order by h.points desc , h. time desc
- limit 5
* This source code was highlighted with Source Code Highlighter .
- select b.points b. time , b.uid, b.answered
- from rating b
- where @points> points
- order by b.points desc , b. time desc
- limit 5)
* This source code was highlighted with Source Code Highlighter .
- drop procedure if exists get_user_rating //
- create procedure get_user_rating ( in uid int unsigned)
- begin
- drop table if exists rating_tmp;
- create temporary table rating_tmp (
- `points` int unsigned,
- ` time` int unsigned,
- `uid` int unsigned,
- `answered int unsigned
- );
- select @points: = points from rating r where q.uid = uid;
- insert into rating_tmp (points, `time`, uid, answered)
- ( select h.points, h. time , h.uid, h.answered
- from rating h
- where @points <h.points
- order by h.points desc , h. time desc
- limit 5)
- union
- ( select points, `time`, uid, answered from r1 rating where r1.uid = uid)
- union
- ( select b.points, b. time , b.uid, b.answered
- from rating b
- where @points> points
- order by b.points desc , b. time desc
- limit 5)
- order by points desc , ` time` desc ;
- end //
* This source code was highlighted with Source Code Highlighter .
- call get_user_rating (1);
- select * from rating_tmp;
Source: https://habr.com/ru/post/79340/
All Articles