SQL GROUP BY Clause
The SQL GROUP BY Clause is used along with the group functions to retrieve data grouped according to one or more columns.
For Example: If you want to know the total amount of salary spent on each department, the query would be:
SELECT dept, SUM (salary)
FROM employee
GROUP BY dept;
The output would be like:
dept salary
------------------------------
Electrical 25000
Electronics 55000
Aeronautics 35000
InfoTech 30000
NOTE: The group by clause should contain all the columns in the select list expect those used along with the group functions.
SELECT location, dept, SUM (salary)
FROM employee
GROUP BY location, dept;
The output would be like:
location dept salary
------------- --------------- -----------
Bangalore Electrical 25000
Bangalore Electronics 55000
Mysore Aeronautics 35000
Mangalore InfoTech 30000
Showing posts with label SQL GROUP BY Clause. Show all posts
Showing posts with label SQL GROUP BY Clause. Show all posts
Sunday, 15 May 2011
Subscribe to:
Posts (Atom)
VMware Cloud Learning Video's
Here is a nice summary list of all VMworld US 2018 Breakout session with the respective video playback & download URLs. Enjoy! Bra...
-
Different types of bra Welcome to this post, we are here to help you with the different types of bras out there and help you make the ...
-
Mens Fashion Wear Hugo Boss is one of the leading designers of high-end menswear in the world today, but the company has a checkered ...
-
Tirukkuraḷ Tirukkuṛaḷ ( Tamil : திருக்குறள் also known as the Kural ), sometimes spelt 'Thirukkural, is a classic of couplets or Kur...