search

Home  >  Q&A  >  body text

How to get the highest value, lowest value and average value in mysql in php

There are two fields in database table A, one is the category, and the other is the price
How to calculate the highest value, lowest value, and average price of No. 11 in the category in PHP
One category corresponds to N pieces of price data such as
11, 100
2, 120
11, 101
11, 101
11, 55
11, 99
5, 88
2, 103
11, 170
5, 98

给我你的怀抱给我你的怀抱2842 days ago893

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-18 10:53:53

    //数据库连接省略
    $data=mysql_query("select MAX(price),MIN(price),AVG(price) from goods where category=11");
    $row_data=mysql_fetch_row($data);
    echo 'MAX:'.$row_data[0].' MIN:'.$row_data[1].' AVG'.$row_data[2];

    reply
    0
  • 阿神

    阿神2017-05-18 10:53:53

    select MAX(price),MIN(price),AVG(price) where category=11

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-18 10:53:53

    I think it will be easier to find the answer if you remove php when searching and simply think of it as a sql question

    reply
    0
  • Cancelreply