Reputation: 11
If I want to know the total amount of salary on each customer, then GROUP BY query would be as follows:
SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;
But, if I don't want sum of salaries and just need to look all salaries grouped by name then what will be query or approach?
Upvotes: 1
Views: 150
Reputation: 332
If you want to retrieve name and variation of salary for each customers (grouped by name and salary). You can try this.
SELECT name, salary FROM customers GROUP BY name, salary;
Upvotes: 0
Reputation: 1022
Try to use GROUP BY clause for getting desired results.
SELECT NAME,SALARY FROM CUSTOMERS GROUP BY NAME;
Upvotes: 0
Reputation: 40491
That depends on which salary you want to show..
Option 1 -> maximum:
SELECT NAME, max(SALARY) FROM CUSTOMERS GROUP BY NAME;
Option 2 -> minimum:
SELECT NAME, min(SALARY) FROM CUSTOMERS GROUP BY NAME;
Option 3 -> list of them:
SELECT NAME, group_concat(SALARY separator ',') FROM CUSTOMERS GROUP BY NAME;
And last option -> doesn't matter :
SELECT NAME,SALARY FROM CUSTOMERS GROUP BY NAME;
Upvotes: 1