mysql数据库中某项其中一个值在该项排第几,百分几
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。