MySQL查询顺序

时间:2016-02-09 05:34:41

标签: mysql sql

$SQL->query('SELECT `p`.`name` AS  `name`,
  (SELECT `k`.`value` FROM `player_storage` k WHERE `k`.`key` = 1000  AND `k`.`player_id` = `p`.`id`) AS value
    FROM `player_storage` k, `players` p WHERE `k`.`player_id` = `p`.`id` GROUP BY  `name` ORDER BY CAST(`value` AS SIGNED) DESC LIMIT 0 , 30;

PLAYERS

id | name   
1    test

PLAYER_STORAGE

player_id | key | value 
1          1000   10

查询工作正常唯一的问题是订单不正确,idk为什么。

实施例: enter image description here

1 个答案:

答案 0 :(得分:1)

您的示例将返回两列,您只需订购第二列。