2016-06-30 3 views
0
Id|product_name|product_group |sale_Amnt(INR) 
------------------------------------------------ 
1| p1  | Cosmetic  |4485 
2| p2  | Cosmetic  |8525 
3| p3  | Health   |12589 
4| p4  | Health   |5895 
5| p5  | Home Appliances|9858 
6| p6  | Home Appliances|11589 

Ich möchte eine SQL-Abfrage holen Product_Group höchste Verkaufsmenge mitSQL-Abfrage Produkt mit der höchsten Verkaufsgruppe holen weise

Antwort

0

es so sein sollte;)

select t1.* 
from yourtable t1 
inner join (
    select max(`sale_Amnt(INR)`) as `sale_Amnt(INR)`, product_group 
    from yourtable 
    group by product_group 
) t2 on t2.product_group = t1.product_group and t2.`sale_Amnt(INR)` = t1.`sale_Amnt(INR)` 

Das Ergebnis dieser Abfrage folgt:

| Id | product_name | product_group | sale_Amnt(INR) | 
|----|--------------|-----------------|----------------| 
| 2 |   p2 |  Cosmetic |  8525  | 
| 3 |   p3 |   Health |  12589  | 
| 6 |   p6 | Home Appliances |  11589  | 
0

USE INNER QUERY TO GROUP BY und ORDER BY

SELECT * FROM (SELECT Product_Group, SUM (sale_Amnt) FROM TABLE GROUP BY Product_Group ORDER BY SUM (sale_Amnt) DESC) R LIMIT 1

+0

wenn Sie alle Produkte, um nach Produktgruppen erhalten möchten ausführen nur die innere wählen –

Verwandte Themen