SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Query throwing me for a loop...
-
Jan 18, 2005, 15:00 #1
- Join Date
- Aug 2000
- Location
- Houston, TX, USA
- Posts
- 6,455
- Mentioned
- 11 Post(s)
- Tagged
- 0 Thread(s)
Query throwing me for a loop...
Alright, I have a table that looks like:
Code:order_id | prod_id | prod_ppu | quantity
I am just at a loss here. I hope my explanation is clear.
Any ideas?
P.S. - I can't use subqueries...ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
-
Jan 18, 2005, 15:56 #2
- Join Date
- Jun 2003
- Location
- Melbourne, AU
- Posts
- 1,142
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Is it not as simple as...
Code:SELECT order_id, prod_id, prod_ppu, quantity FROM yourtable ORDER BY quantity DESC LIMIT 6
Lats...
-
Jan 18, 2005, 16:49 #3
- Join Date
- Aug 2000
- Location
- Houston, TX, USA
- Posts
- 6,455
- Mentioned
- 11 Post(s)
- Tagged
- 0 Thread(s)
No, because there will be multiple records in the table with the same order_id (just a different prod_id).
ssegraves [at] gmail.com
On Image Use, Abuse, and Where We're Headed
stephan | XMLHttpRequest Basics
flickr | last.fm | Cogentas, LLC
-
Jan 18, 2005, 18:06 #4
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
Code:select prod_id , sum(quantity) as totalqty from yourtable group by prod_id order by totalqty desc limit 6
-
Jan 18, 2005, 22:55 #5
- Join Date
- Jun 2002
- Location
- Riding the electron wave
- Posts
- 372
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Excellent! I was wrestling with a similar issue.
Ducharme's Axiom: "If you view your problem closely
enough, you will recognize yourself as part of the problem."
Bookmarks