/* Aggregate functions */ /* SUM(), COUNT(), AVG(), MIN(), MAX() */ SELECT SUM(price) FROM course; SELECT SUM(price) /* only some of the rows */ FROM course WHERE price > 1000; SELECT COUNT(*) /* Count all rows */ FROM student; SELECT COUNT(lname) /* count number of students */ FROM student; SELECT COUNT(fname), COUNT( DISTINCT fname) /* count first names, */ FROM student; /* and distinct first names */ SELECT SUM(price), COUNT(price), AVG(price) FROM course WHERE price > 1000; SELECT MIN(price) /* the lowest priced course */ FROM course; SELECT MIN(price), description /* you cannot do this */ FROM course; /* all columns must have aggr func */ SELECT MIN(price), MIN(description) /* this does not give you information */ FROM course; /* about the lowest priced course */ SELECT price, description FROM course /* to get the lowest priced course */ ORDER BY price /* sort it by price */ LIMIT 1; /* MySQL limit output to 1 row */ SELECT price, description FROM course ORDER BY price FETCH FIRST 1 ROW ONLY; /* Oracle limit the output */ SELECT price, description /* or you can use a sub-query */ FROM course where price = (SELECT MIN(price) FROM course);