简体   繁体   中英

Order by score total ASC

I could not get rid of a problem and want your help.

This is what I want to do briefly;

There are job postings in Table A, and these job posts have ratings in table B. When I list the job postings, I want to list the job postings by the highest percentage percentage.

$query = $db->query("SELECT job_listing.id,
        FROM job_listing
            LEFT JOIN job_order_ratings ON job_order_ratings.job_id = job_listing.id
        WHERE job_listing.job_status = 2 
        ORDER BY *** ASC")->fetchAll(PDO::FETCH_ASSOC);

score table

I normally calculate the score rating of a job this way. I want to list the points according to the total rate while listing

public function rateTotal($rate1, $rate2, $rate3, $count= '')
{
      $rate_total = $rate1 + $rate2 + $rate3;
      $total = $rate_total / $count;
      return number_format(round(($total / 3), 1), 1, '.', '');
}

Since there are three ratings, I divide it into the last three

When I list job postings in sql query, I want it to list by percentage. It has to calculate just like I did in the rateTotal function.

I'm sorry for my bad english

$sql = "SELECT
              job_listing.id,
              FORMAT((SUM(column1 + column2 + column3)/ COUNT(column)) / 3, 2) AS 'rating
        FROM job_listing
        LEFT JOIN job_order_ratings ON job_order_ratings.job_id = 
                 job_listing.id
    WHERE job_listing.job_status = 2 ORDER BY job_order_ratings.field DESC"

Did you try this way? When u use ASC (ascending), you will order numbers from smaller to bigger, if you use DESC (descending) is from bigger to smaller number 10,9,8,7,6,5...

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