Friday, March 12, 2010

The Tedious Questions..

Q: In SQL what does 'Group By' do?

A: The GROUP BY statement is used in conjunction with the aggregate functions(avg, sum, etc) to group the result-set by one or more columns. Note that only the columns used by the GROUP BY statement can be used in the SELECT statement.

fred| 100
bob| 100
fred| 400

SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer

fred| 500
bob| 400