Monday, February 8, 2010

SQL GROUP BY - Introduction and syntax

Explain the SQL GROUP BY statement. Write SQL syntax for the SQL GROUP BY statement along with an example.

GROUP BY: It is used with aggregate functions to group the result-set by one or more columns.

Syntax:
SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name

Example:
SELECT Emp_id,joiningdt,SUM(salary) FROM employee GROUP BY emp_id,joiningdt

No comments:

Post a Comment