首页 > 代码库 > mysql数据库中某项其中一个值在该项排第几,百分几
mysql数据库中某项其中一个值在该项排第几,百分几
SQL 如下:
sql 1.
SELECT X.USER_ID, X.TOTAL_NO, X.ORDER_NO, X.ORDER_NO / X.TOTAL_NO AS PERCENTAGE_NOFROM (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 ) XWHERE USER_ID = 3008
sql2.
SELECT X.COMMENT_ID, X.TOTAL_NO, ORDER_NO, IFNULL(X.ORDER_NO / X.TOTAL_NO, 1) AS PERCENTAGE_NOFROM (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 ) XWHERE COMMENT_ID = 15
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。