aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 1476
    
  11

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
 
Similar Threads
Bit Conversion
The Four Fours Problem
Prime numbers
Intra Ranch Go Game!
pattren