mysql投票总排行_MySQL存储过程获取记录排名(一般用于投票系统)

更新时间:2023-06-10 23:31:10 阅读: 评论:0

孕妇打嗝mysql投票总排⾏_MySQL存储过程获取记录排名(⼀般⽤于
投票系统)
MySQL存储过程获取记录排名(⼀般⽤于投票系统) 原理 计算当前学校的票数,暂且记作a 计算票数⼤于⾃⼰的学校数⽬,暂且记作b,如果b=0,则⾃⼰票数排名第⼀ 计算票数⼩于⾃⼰的学校数⽬,暂且记作c,如果c=0,则⾃⼰票数排名最后 如果b!=0c!=0,那么b+c就是
MySQL存储过程获取记录排名(⼀般⽤于投票系统)
原理
计算当前学校的票数,暂且记作a
计算票数⼤于⾃⼰的学校数⽬,暂且记作b,如果b=0,则⾃⼰票数排名第⼀
计算票数⼩于⾃⼰的学校数⽬,暂且记作c,如果c=0,则⾃⼰票数排名最后
如果b != 0 && c != 0,那么b+c就是⾃⼰的票数排名
CREATE PROCEDURE `get_rank`(IN `school` INT)大大姐
BEGIN
SET @votes = (SELECT COUNT(tcl_vote.vote_id) AS counts FROM tcl_works LEFT JOIN tcl_vote ON tcl_vote.works_id =
tcl_works.works_id WHERE tcl_works.school_id=school);
SET @gt = (
SELECT
COUNT(*)
FROM
(
SELECT
黑龙江省高考分数线tcl_works.school_id,
如何启用宏功能COUNT(tcl_vote.vote_id) AS votes
FROM
tcl_works
LEFT JOIN tcl_vote ON tcl_vote.works_id = tcl_works.works_id
GROUP BY
tcl_works.school_id
HAVING
votes > @votes
ORDER BY
votes DESC
)
AS xxx
)
;
IF @gt = 0
THEN
SET @rank = 1;
SELECT @rank AS rank;
ELSE
SET @lt = (
SELECT
COUNT(*)
火开头成语FROM
(
冯老师SELECT
tcl_works.school_id,
COUNT(tcl_vote.vote_id) AS votes
FROM
tcl_works
LEFT JOIN tcl_vote ON tcl_vote.works_id = tcl_works.works_id GROUP BY
tcl_works.school_id
HAVING
votes < @votes
ORDER BY
votes DESC
)
AS xxx
);
IF @lt = 0
光端机THEN
SET @rank =(SELECT COUNT(*) FROM tcl_school LIMIT 1); SELECT @rank AS rank;
ELSE
劳动心得体会SET @rank = (@gt+@lt);
SELECT @rank AS rank;
END IF;
END IF;

本文发布于:2023-06-10 23:31:10,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1032846.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:票数   计算   排名   黑龙江省   打嗝
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图