Thursday, April 7, 2011

AGGREGATES

test=> SELECT * FROM friend ORDER BY firstname;

test=> SELECT COUNT(*) FROM friend;

test=> SELECT SUM(age) FROM friend;

test=> SELECT MIN(age) FROM friend;

test=> SELECT AVG(age) FROM friend;

 => SELECT state, MIN(age), MAX(age), AVG(age)
-> FROM friend
-> GROUP BY state
-> ORDER BY 4 DESC;

test=> SELECT state, COUNT(*)
test-> FROM friend
test-> GROUP BY state
test-> HAVING COUNT(*) > 1
test-> ORDER BY state;
 

0 comments:

Post a Comment