如何选择列的最高相对值?

时间:2017-04-20 14:05:56

标签: php mysql select conditional relative

我想选择满足条件的“价格”栏中值最高的行。

使用如下所示的MAX()对我来说不起作用,因为它会缩小该列的最高绝对值。

"SELECT * FROM parts_list WHERE " . (implode(' = 1 AND ', $utilization)) . " = 1 AND (part_price = (SELECT MAX(part_price) FROM parts_list))"

我只希望它选择那些具有最高价值的那个'part_price'的那个满满的:

 . (implode(' = 1 AND ', $utilization)) . " = 1 

2 个答案:

答案 0 :(得分:1)

您可以先ORDER BY part_price DESC然后使用TOP 1来获取第一行。

答案 1 :(得分:0)

发布后仅2分钟,我有了一个想法:

"SELECT MAX(part_price) * FROM parts_list WHERE " . (implode(' = 1 AND ', $utilization)) . " = 1 AND (part_price = (SELECT MAX(part_price) FROM parts_list WHERE ".implode(' = 1 AND ', $utilization)." = 1))");