-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql-functions.sql
More file actions
102 lines (60 loc) · 1.88 KB
/
sql-functions.sql
File metadata and controls
102 lines (60 loc) · 1.88 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
SQL ( Functions )
*/
-- functions - to perform a specific task.
-- link : techonthenet.com/mysql (functions list )
-----------------------------------------------------------------
-- if we want to count the total no.of . employees
SELECT COUNT(*)
from employee;
-- it wiil display count of employees [ for e.g., 25 like that ]
SELECT COUNT(*) TOTAL
from employee;
-- it will display the TOTAL 25 . like that
SELECT COUNT(*) MANAGER
FROM employee
WHERE JOB_ROLE="MANAGER";
-- it will display the manager role count and it will be display [ for e.g., MANAGERS 5 like that ]
SELECT AVG(SALARY)
FROM employee
WHERE JOB_ROLE="INTERN";
-- it will display the average salary of total interns
SELECT SUM(SALARY)
FROM employee
WHERE JOB_ROLE="HR";
-- it will display the total sum of salary for HR
/*
FOR E.G.,
HR - 5000
HR - 6000
HR - 6700
IT WILL DISPLAY THE SUM OF SALARY FRO HR = 17700
LIKE THAT..,
*/
SELECT MAX(SALARY)
FROM employee;
SELECT MIN(SALARY)
FROM employee;
-- it will display the max and min salary of total employees list
-- these are aggregate funtions, which are used most commonly.
--------------------------------------------------------------------
-- STRING
SELECT NAME,SALARY
FROM employee;
-- it will print normally name and salary list
-- if i want the name as uppercase means , we can use this
SELECT UCASE(NAME),SALARY
FROM employee;
SELECT UCASE(NAME) EMP_NAME,SALARY
FROM employee;
-- it will display the name as EMP_NAME that called as ALIAS NAME
SELECT NAME,CHAR_LENGTH(NAME) CHAR_COUNT_NAME
FROM employee;
-- it will display the name of the character count in another column
-- concatenate --
SELECT NAME,CONCAT('Rs.',FORMAT(SALARY,0)) SALARY
FROM employee;
SELECT NAME,LEFT(JOB_ROLE,3)
FROM employee;
-- it will display the job role first 3 letter for e.g., manager means MAN
-------------------------------------------------------------------