我有一个用 php 编写的 SQL 请求,我想对其进行优化。
我认为这是可能的,因为一切都在同一张桌子上。我不是 SQL 专家,我使用包括“share”和“results”/“sub”/“partial”在内的关键字进行的搜索没有帮助。
SELECT C0.bestScore, C1.playerScore, C2.playerRank FROM
(SELECT MAX(score) AS bestScore FROM `{$l_tableName}`) C0,
(SELECT MAX(score) AS playerScore FROM `{$l_tableName}` WHERE player_id = {$l_playerId}) C1,
(SELECT COUNT(*)+1 AS playerRank FROM `{$l_tableName}` WHERE score > (SELECT MAX(score) FROM `{$l_tableName}` WHERE player_id = {$l_playerId}) ) C2;
谢谢