如何在一行上写下这个2 SELECT
。我需要获得2个查询。第一个问题是:
SELECT (COUNT(*) + 1) AS rank FROM `rang_info` WHERE `player_kills` > (SELECT `player_kills` FROM `rang_info` WHERE `player_name` = '%s')
第二个问题是:
SELECT COUNT(*) FROM `rang_info`
答案 0 :(得分:1)
使用UNION
。应该工作:
SELECT (COUNT(*) + 1) AS rank FROM `rang_info` WHERE `player_kills` > (SELECT `player_kills` FROM `rang_info` WHERE `player_name` = '%s')
UNION
SELECT COUNT(*) FROM `rang_info`
答案 1 :(得分:0)
如果你想要一行,那么下面的内容应该可以正常工作
SELECT SUM(rank) AS rank, SUM(total) AS total
FROM
(SELECT (COUNT(*) + 1) AS rank, 0 AS total FROM `rang_info`
WHERE `player_kills` > (SELECT `player_kills` FROM `rang_info` WHERE `player_name` = '%s')
UNION
SELECT 0 AS rank, COUNT(*) AS total FROM `rang_info`) AS temptable