我想选择满足条件的“价格”栏中值最高的行。
使用如下所示的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
答案 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))");