Friday, November 27, 2015

SQL -- Aggregate Functions (Group By)


How many people are in each unique state in the customers table? Select the state and display the number of people in each. 



SELECT state, count(state)
FROM customers
GROUP BY state;
 

 

SQL -- Aggregate Functions (MIN)


For all of the tents that were ordered in the items_ordered table, what is the price of the lowest tent? Hint: Your query should return the price only.


SELECT MIN(price)
FROM items_ordered
WHERE item = 'Tent';


SQL -- Aggregate Functions (AVG)



Select the average price of all of the items ordered that were purchased in the month of Dec.



SELECT AVG(price)
FROM items_ordered
WHERE order_date LIKE '%Dec%';