search

Home  >  Q&A  >  body text

php - Why is mysql calculation of maximum and minimum values ​​inaccurate?

Calculate through the following sql statement, why are some of the results inaccurate

    public function get_avgprice_item($category_id){
        $sql = "SELECT MAX(yj) as m_max, AVG(yj) as m_avg, Min(yj) as m_min FROM " . $this->get_table('item') . ' where category_id = ' . intval($category_id);
         return $this->query_row($sql);
    }

No misplacement,

Why are the calculated results like this?

滿天的星座滿天的星座2809 days ago494

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:00:47

    category_id is not the primary key. If it is, just taking one will have no statistical significance. If not, then where is the group by? It’s best to post all the code

    reply
    0
  • Cancelreply