Presentation is loading. Please wait.

Presentation is loading. Please wait.

Built in Functions Massaging the data.

Similar presentations


Presentation on theme: "Built in Functions Massaging the data."— Presentation transcript:

1 Built in Functions Massaging the data

2 Functions SQL includes several built in functions
They all operate with the same pattern SELECT FunctionName(Function arguments) FROM Tablename Function can be nested inside of each other SELECT MAX(SUM(Rate*Hours)

3 ALIASING You can give a return column generated by a function a name or Alias SELECT MAX(Rate) AS Highest SELECT MAX(Rate) “Highest”

4 Most Common Functions COUNT MAX MIN SUM AVG

5 Count COUNT counts the number of rows that meet a certain criteria.
It can be used on textual as well as numeric data SELECT Count(*) FROM Orders SELECT COUNT(CarrierCode) as ALASKA FROM ItinerayDetail WHERE CarrierCode=‘ALA’

6 MAX MAX returns the largest value in a column.
It can only be used with numeric fields and dates SELECT MAX(Price) FROM Inventory

7 MIN Returns the lowest value in a column (again numeric or date)
SELECT MIN(RATE) FROM HourlyRate

8 SUM SUM Returns the total of numeric column
SELECT SUM(points) FROM Assignment WHERE StudentID=‘ ’

9 AVG AVG Returns the mean Average of a numeric column
SELECT AVG(heartrate) FROM Excercise

10 Aggregate Functions All the functions that we have looked at are called aggregate functions That means they work on groups of rows or values, rather than just one row or one value

11 GroupBy If you include any columns in the SELECT of a query with an aggregate function you must GROUP BY those columns SELECT StudentID, SUM(points) FROM Assignments GROUP BY StudentID

12 Having Like the WHERE clause, but WHERE operates on individual records HAVING operates on Aggregrate (grouped) records SELECT EmployeeID, COUNT(OrderID) AS NumOrders FROM ORDERS GROUP BY EmployeeID HAVING COUNT(OrderID)>100

13 Example SubQuery SELECT Orderid, unitprice FROM SaleDetail
WHERE Unitprice= (SELECT MAX (UnitPrice) FROM SaleDetail


Download ppt "Built in Functions Massaging the data."

Similar presentations


Ads by Google