更新时间:2023-02-26 10:45:54
在此处找到解决方案: https://***.com/a/4685040/1266457
Found the solution here: https://***.com/a/4685040/1266457
谢谢:)
要解决:
// Prepare and execute the variables first
$sql = "
SET @prev_value = NULL;
SET @rank_count = 0;
SET @rank_increasing = 0;
";
$sth = $dbh->prepare($sql);
$sth->execute();
// Run the main query
$sql = "
SELECT a.*
, @rank_increasing := @rank_increasing + 1 AS row_num
, CASE
WHEN @prev_value = score
THEN @rank_count
WHEN @prev_value := score
THEN @rank_count := @rank_increasing
END AS rank
FROM (
-- INLINE VIEW --
) a
"; ...