Saturday, October 24, 2015

SQL -- Aggregate Functions

The following example summarize the numeric results of a column. Here a list of agregate funtions:


MIN
returns the smallest value in a given column
MAX
returns the largest value in a given column
SUM
returns the sum of the numeric values in a given column
AVG
returns the average value of a given column
COUNT
returns the total number of values in a given column
COUNT(*)
returns the number of rows in a table





Here is an example of selecting the maximum price of any item ordered in the item_ordered table.



SELECT MAX(price)
FROM items_ordered;




Thursday, October 15, 2015

SQL -- Selecting Distinct

The following example displays a listing of each of the unique (distinct) items from the items_ordered table.






Select the distinct items in the items_ordered table. In other words, display a listing of each of the unique items from the items_ordered table.


SELECT DISTINCT item
FROM items_ordered;


 



SQL -- Select Statement




1. Select the customerid, order_date, and item values from the items_ordered table for any items in the item column that start with the letter "S".

SELECT customerid, order_date, item, price
FROM items_ordered
WHERE item LIKE 'S%';