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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.