Pages

Wednesday, January 19, 2011

GROUP BY

GROUP BY
--==========================================[GROUP BY]======================================================================
--GROUP BY statement is used along with the SQL aggregate functions like SUM to provide
--means of grouping the result dataset by certain database table column(s).

--Without Group By----
SELECT SUM(EmailPromotion) AS EmailPromoGroup
FROM Person.Contact

--With Group By But No Correspoding Grouping----
SELECT SUM(EmailPromotion) AS EmailPromoGroup
FROM Person.Contact
Group By Title

---With Group By and With additional column of the Group(Title)----
SELECT Title, SUM(EmailPromotion) AS EmailPromoGroup
FROM Person.Contact
Group By Title

No comments:

Post a Comment