简体   繁体   中英

Want to get lowest value from sql

In my database there are 5 values: 50, 75, 95, 125 and 200. When I query the minimum value I get 125, but I should get 50.

Here is my code:

$result_upTICKET = mysql_query("SELECT ID, EID, COMMISSION, MIN(PRICE) as PRICE FROM `tickets` WHERE EID='$EID_UPcoMing' AND STATUS='1'");

while($row_upTICKET = mysql_fetch_array($result_upTICKET))
{
    $PRICE_upTICKET= $row_upTICKET['PRICE'];
    $COMMISSION_upTICKET= $row_upTICKET['COMMISSION'];
}

What did I get wrong?

试试这个

SELECT ID, EID, COMMISSION, PRICE FROM `tickets` WHERE EID='$EID_UPcoMing' AND STATUS='1' ORDER BY PRICE ASC LIMIT 1

you are using where condition also. It filters rows first then apply/Select columns and min . I am sure that your where condition pull out row with price 50 and that's why min is coming as 125 instead of 50

Please execute your query like,We need to convert into interger

mysql_query("SELECT ID, EID, COMMISSION, MIN(CONVERT(PRICE, SIGNED INTEGER)) as PRICE FROM tickets WHERE EID='$EID_UPcoMing' AND STATUS='1'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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