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
SELECT X.COMMENT_ID, X.TOTAL_NO, MAX(X.ORDER_NO) AS ORDER_NO , IFNULL(MAX(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
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
WHERE to_days(t.CREATE_TIME) >= to_days(now()) and t.COMMENT_SPENDING < 111 ORDER BY t.COMMENT_SPENDING ,t.COMMENT_ID
) X
demo4 :
SELECT SUM(TODAY_USER_SHOW_DETAIL_COUNT), COUNT(*) AS TODAY_SHOW_DETAIL_USER_COUNT, @descRowNum AS CHOWN_ORDER_NO, @descSumSpending AS CHOWN_SUM_SPENDING
FROM (SELECT IF(USER_ORDER.USER_ID = 3005, @descRowNum := (@rowNum := @rowNum + 1), @rowNum := @rowNum + 1) AS ORDER_NO, IF(USER_ORDER.USER_ID = 3005, @descSumSpending := USER_ORDER.TODAY_USER_SPENDING, USER_ORDER.TODAY_USER_SPENDING) AS TODAY_USER_SPENDING, USER_ORDER.USER_ID, USER_ORDER.TODAY_USER_SHOW_DETAIL_COUNT
FROM (SELECT @rowNum := 0
) R, (SELECT user_detail.USER_ID, COUNT(user_detail.USER_ID) AS TODAY_USER_SHOW_DETAIL_COUNT, SUM(user_detail.COMMENT_SPENDING) AS TODAY_USER_SPENDING
FROM (SELECT @rowNum := 0
) R, (SELECT USER_ID, COMMENT_SPENDING
FROM T_SD_COMMENT
WHERE TO_DAYS(CREATE_TIME) >= TO_DAYS(NOW())
UNION
SELECT 3005, 444.4
) user_detail
GROUP BY user_detail.USER_ID
ORDER BY TODAY_USER_SPENDING
) USER_ORDER
) O