Jump to content

Need to order by Sum(rate)


miguelfsf
Go to solution Solved by Barand,

Recommended Posts

Hello,

 

Lets if i can explain this well (sorry for bad english!)

 

I have two differents tables on my db "Mixtapes" and "Vote" and i want to order them in DESC order by the SUM of all rate values that belong to a specific mixtape.

 

Mixtapes:

id

name

status

(etc)

 

Vote

id_mixtape  // id_mixtape = id in Mixtapes table

rate

 

This is the query that im using but its not listing in Desc order, dont know why:

"SELECT id,name FROM mixtape WHERE status=1 AND id IN(SELECT id_mixtape FROM vote GROUP BY id_mixtape ORDER BY SUM(rate) DESC) LIMIT 12"
Link to comment
Share on other sites

Didnt work.. It has only listed one mixtape with the sum of all rates, but i want the rate that is specific to that mixtape

 

 

I tested the sql code on my phpmyadmin and for total i got 38 and it should be 6. 

For example, this is what i have on my vote table:

 

Sem_T_tulo.png

 

 

The total of the id_mixtape number 4 should be 20+12=32 and the total of id_mixtape number 3 should be 6, and then it orders each mixtape by this value on DESC order.

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.