选择值大于当前字段值的所有字段

时间:2012-08-13 20:26:12

标签: mysql mysql5

我有一张看起来像这样的表。

| path_id |步骤| point_id | delay_time | stand_time |访问|

| 202 | 1 | 111 | 0 | 0 | 7 |

以步骤顺序列出了point_id。 例如:111 - 步骤1,181 - 步骤2等

我需要编写一个带有point_id的查询,选择在具有给定值的所有path_id中具有更高步长的所有值,并返回一组point_id的分组。

我目前正在使用此查询

SELECT DISTINCT `pdb`.`point_id` AS `id` 
FROM `path_detail` AS `pda` INNER JOIN 
`path_detail` AS `pdb` ON pda.path_id = pdb.path_id 
 AND pda.step < pdb.step
WHERE 
(pda.point_id = 111) 
GROUP BY `pdb`.`path_id`

这似乎不太可靠。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试:

SELECT Distinct `pdb`.`point_id` AS `id` 
FROM `path_detail` AS `pda`, `path_detail` AS `pdb`  
WHERE 
pda.point_id = 111
AND pda.path_id = pdb.path_id 
AND pda.step < pdb.step
Order by `pdb`.`point_id` ASC