-
Notifications
You must be signed in to change notification settings - Fork 0
/
(3) Query(Select).sql
147 lines (98 loc) · 3.31 KB
/
(3) Query(Select).sql
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- 1)
use Akshen;
show tables;
select * from resumes;
select Skills from resumes;
select Education from resumes where Project="DL";
-- 2)
create database hr_emp;
use hr_emp;
create table employees
(employee_id int unsigned not null,
first_name varchar(25) not null,
last_name varchar(25) not null,
email varchar(25) not null,
phone_number int unsigned not null,
hire_date date not null,
job_id int unsigned not null,
salary decimal(8,2) unsigned not null,
manager_id int unsigned not null,
department_id int unsigned not null,
primary key(employee_id)
);
show tables;
describe employees;
-- 3)
use hr;
show tables;
select*from employees;
select*from employees where employee_id=95;
select*from employees where first_name='Steven';
select*from employees where hire_date < '1990-01-03';
select phone_number from employees where year(hire_date)='1990';
select*from employees where year(hire_date)>1990 and salary>10000;
select first_name, email, salary from employees
where salary>10000 and employee_id>150;
select first_name from employees where salary between 10000 and 20000;
select first_name, salary from employees where salary in (10000,20000);
select*from employees where first_name in ('Peter', 'Hermann');
select*from employees where job_id not in ('ST_CLERK');
-- like, not like
select*from employees where first_name like '%a';
select*from employees where first_name like 'b%';
select*from employees where first_name like '%a%';
select*from employees where first_name like '%a__';
select*from employees where first_name like '__a%';
select*from employees where first_name not like '%a';
select*from employees where commission_pct is not null;
select*from employees where commission_pct is null;
select employee_id, first_name, last_name, job_id Job_Id from employees;
-- column alias: only changes in the current statement not in the database
-- logical operator (and,or,not)
select*from employees where last_name = 'Patel' and salary='2500';
select*from employees where last_name = 'Patel' and salary='5000';
select*from employees where last_name = 'Patel' or salary='20000';
select*from employees where not(last_name = 'Patel');
-- relational operator
select*from employees where salary = 24000;
select*from employees where salary != 24000;
select*from employees where salary <> 24000 or salary = 24000;
select first_name, salary Salaries from employees where salary <= 2400;
select last_name Last_Name, salary from employees where salary >= 15000 and salary <=20000;
-- order by
select*from employees
order by first_name;
select first_name, last_name from employees
order by last_name desc;
select*from employees
order by first_name desc;
select*from employees
order by last_name desc;
select * from employees
order by first_name desc, last_name desc;
-- limit
select email, job_id from employees
order by first_name
limit 5;
-- list emp getting least salary
select * from employees
order by salary asc
limit 5;
-- list emp getting highest salary
select*from employees
order by salary desc
limit 5;
-- offset
select*from employees
order by salary desc;
select*from employees
order by salary desc
limit 6 offset 7;
select*from employees
order by phone_number;
select*from employees
order by phone_number
limit 5 offset 8;
select*from employees
limit 5,5;
select first_name, last_name, salary, salary * 0.5 Salary from employees;