It's not a secret anymore!*
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: 1716
    
  14

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a sql query