Jump to content

[SOLVED] Ordering by highest value


Canman2005

Recommended Posts

Hi all

 

I have a simple table which looks like

 

ID    USER      PRICE

1    10          12.00

2    21          5.00

3    21          10.00

 

What I want to do is run a query and return all results with the `USER` with the highest value at the top.

 

So with my example above, `USER` ID 10 has a total of 12.00 (ROW 1) and `USER` has a total of 15.00 (5.00 + 10.00) (ROW 2 and 3)

 

So it would therefore return

 

USER  TOTAL

21      15.00

10      12.00

 

Can anyone help?

 

Much love

 

Link to comment
https://forums.phpfreaks.com/topic/131357-solved-ordering-by-highest-value/
Share on other sites

Am I seeing things?  I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user?  I was just about to post it and I swear it just changed...  ???

 

i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me :)

Am I seeing things?  I know it doesn't say *edit* but did you switch your SELECT & GROUP BY statements from id to user?  I was just about to post it and I swear it just changed...  ???

 

i did change it...noticed right after i posted...thought i would sneak it in there before anyone caught me :)

 

Hehe, just wanted to make sure I wasn't seeing things.  :o

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.