码迷,mamicode.com
首页 > 数据库 > 详细

mysql数据库中某项其中一个值在该项排第几,百分几

时间:2014-07-06 19:22:30      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   数据   数据库   

 

SQL 如下:

 sql 1.

SELECT X.USER_ID, X.TOTAL_NO, X.ORDER_NO, X.ORDER_NO / X.TOTAL_NO AS PERCENTAGE_NO
FROM (SELECT @rowNum := @rowNum + 1 AS ORDER_NO, @rowCount AS TOTAL_NO, USER_ID
    FROM T_SD_USER, (SELECT @rowNum := 0
        ) b, (SELECT @rowCount := (
                SELECT COUNT(*)
                FROM T_SD_USER
                )
        ) c
    ORDER BY USER_ID DESC
    ) X
WHERE USER_ID = 3008

 

sql2.

SELECT X.COMMENT_ID, X.TOTAL_NO, ORDER_NO, IFNULL(X.ORDER_NO / X.TOTAL_NO, 1) AS PERCENTAGE_NO
FROM (SELECT @rowNum := @rowNum + 1 AS ORDER_NO, @rowCount AS TOTAL_NO, t.COMMENT_ID, t.COMMENT_SPENDING
    FROM T_SD_COMMENT t, (SELECT @rowNum := 0
        ) b, (SELECT @rowCount := (
                SELECT COUNT(*)
                FROM T_SD_COMMENT
                WHERE to_days(CREATE_TIME) >= to_days(now())
                )
        ) c
    ORDER BY CREATE_TIME DESC
    ) X
WHERE COMMENT_ID = 15

 

 

 

 

 

 

 

 

 

 

 

 

 

 

mysql数据库中某项其中一个值在该项排第几,百分几,布布扣,bubuko.com

mysql数据库中某项其中一个值在该项排第几,百分几

标签:des   style   blog   color   数据   数据库   

原文地址:http://www.cnblogs.com/mjorcen/p/3824909.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!