Jump to content

Confused what this query is doing


pouncer

Recommended Posts

SELECT
    count(*) AS tot_people_per_rating,
    rating

This part of the query tell it to return two values. The first value is the number of records that are grouped together - more on this later. The 2nd value is from the rating field

 

FROM
    item_rating

This tells it what table to grab the data from

 

WHERE
    item_id='$item_id'

This instructs the query to only grab values for results where the item_id is a specific value

 

GROUP BY rating

This instructs the query to group records together where they have the same rating.

 

Well, in this case it is counting the records in each grouped result. So, if there are 5 records in the table with the rating of 'B' your result set will include 1 record that represents those five records because of the GROUP BY clause. And the COUNT function wil create a value of 5. And the same process will create similar results for all other ratings in the table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.