-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic functions
42 lines (37 loc) · 1.26 KB
/
Basic functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#SELECT Statement
# Top, Distinct, Count, As, Max, Min, Avg
SELECT *
FROM EmployeeDemographics
----------------------------------------------------------------------------------
# Top function, say top 3.
SELECT TOP 3 *
FROM EmployeeDemographics
# Error message with Top function, using LIMIT function instead.
SELECT *
FROM EmployeeDemographics
LIMIT 3
----------------------------------------------------------------------------------
# Distinct function. Used to get unique values in a specific column
SELECT DISTINCT (LastName)
FROM EmployeeDemographics
----------------------------------------------------------------------------------
#Count function. Returns non-null values in a column.
SELECT COUNT(FirstName)
FROM EmployeeDemographics
#Note; for COUNT to work, no space between function & parenthesis
----------------------------------------------------------------------------------
#As function. Used to rename a column in a table
SELECT COUNT(FirstName) AS LastnameCount
FROM EmployeeDemographics
----------------------------------------------------------------------------------
SELECT *
FROM EmployeeSalary
#Max function
SELECT MAX(Salary)
FROM EmployeeSalary
#Min function
SELECT MIN(Salary)
FROM EmployeeSalary
#Avg function
SELECT AVG(Salary)
FROM EmployeeSalary