简体   繁体   English

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

[英]How to select highest relative value of column?

I want to select the row which has highest value in column "price" of the ones fullfilling the condition. 我想选择在满足条件的“价格”列中具有最高价值的行。

Using MAX() like shown below doesn't work for me since it's cehcking the highest absolute value of that column. 如下所示,使用MAX()不适用于我,因为它正在计算该列的最高绝对值。

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

I only want it to select the one with the highest value for 'part_price' of the ones which fullfill: 我只希望它选择一个满额商品中“ part_price”值最高的商品:

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

您可以先ORDER BY part_price DESC ,然后使用TOP 1仅获得第一行。

发布后仅两分钟,我有了一个主意:

"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))");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM