This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes Need a sql query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "Need a sql query" Watch "Need a sql query" New topic
Author

Need a sql query

Priyakant Charokar
Ranch Hand

Joined: May 08, 2004
Posts: 58

I have a table:

+--------------+---------+----------+
| product_name | sale_id | quantity |
+--------------+---------+----------+
| IPhone | 4 | 10 |
| IPhone | 10 | 20 |
| IPhone | 5 | 15 |
| IPhone | 11 | 20 |
| IPhone | 6 | 20 |
| Moto | 3 | 8 |
| Moto | 1 | 25 |
| Moto | 2 | 16 |
| Samsung | 8 | 18 |
| Samsung | 9 | 20 |
| Samsung | 7 | 20 |
+--------------+---------+----------+



Want the maximum item sale .... it should return

+--------------+---------+----------+
| product_name | sale_id | quantity |
+--------------+---------+----------+
| IPhone | 4 | 10 |
| IPhone | 10 | 20 |
| IPhone | 5 | 15 |
| IPhone | 11 | 20 |
| IPhone | 6 | 20 |
+--------------+---------+----------+

Please help ... with the query


SCJP, SCWCD, SCMAD, SCEA, OCPJP 7, CSM
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 2205
    
  22

You need to define how you want to group your required output, and what constitutes the "maximum" value for each group. It's not at all clear how you get from your inputs to your expected outputs in your example.

You also need to read about using aggregate functions (like MAX) and GROUP BY in SQL.


No more Blub for me, thank you, Vicar.
 
Have you checked out Aspose?
 
subject: Need a sql query
 
It's not a secret anymore!