• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need a sql query

 
Ranch Hand
Posts: 58
Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic