Repository navigation
Expand file tree
/
Copy pathMysql_task1.sql
More file actions
163 lines (112 loc) · 3.64 KB
/
Copy pathMysql_task1.sql
File metadata and controls
163 lines (112 loc) · 3.64 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
-- part A
create database company_db;
use company_db;
create table employees (
employee_id int primary key,
employee_name varchar(100),
department varchar(50),
salary decimal(10,2),
city varchar(50),
joining_date date,
status varchar(20)
);
desc employees;
show tables;
-- part B
insert into employees
(employee_id, employee_name, department, salary, city, joining_date, status)
values
(101, 'Rahul Patil', 'Development', 45000.00, 'Pune', '2026-01-10', 'Active'), (102, 'Priya Sharma', 'Testing', 38000.00, 'Mumbai', '2026-02-15', 'Active'), (103, 'Amit Joshi', 'Development', 52000.00, 'Pune', '2025-12-05', 'Active'), (104, 'Sneha Kulkarni', 'HR', 35000.00, 'Nashik', '2026-03-20', 'Active'), (105, 'Rohan Deshmukh', 'Support', 30000.00, 'Mumbai', '2026-04-01', 'Inactive'), (106, 'Anjali More', 'Testing', 42000.00, 'Pune', '2026-05-12', 'Active');
-- part C
select * from employees;
select employee_name from employees;
select employee_name, salary from employees;
select employee_name, department, city from employees;
select * from employees where city = 'Pune';
select * from employees where city = 'Mumbai';
select * from employees where department = 'Development';
select * from employees where department = 'Testing';
select * from employees where status = 'Active';
select * from employees where status = 'Inactive';
select * from employees where employee_id = 103;
select * from employees where employee_name = 'Priya Sharma';
select * from employees where salary > 40000;
select * from employees where salary < 40000;
select * from employees where salary = 35000;
select * from employees where salary >= 42000;
select * from employees where city = 'Pune' and status = 'Active';
select * from employees where department = 'Development' and salary > 45000;
select * from employees where city = 'Pune' or city = 'Mumbai';
-- part D
update employees
set salary = 48000
where employee_name = 'Rahul Patil';
update employees
set status = 'Active'
where employee_name = 'Rohan Deshmukh';
update employees
set city = 'Pune'
where employee_name = 'Sneha Kulkarni';
update employees
set department = 'Development'
where employee_name = 'Priya Sharma';
update employees
set salary = 45000
where employee_id = 106;
update employees
set salary = salary + 3000
where employee_id = 103;
update employees
set salary = salary + 2000
where department = 'Testing';
update employees
set city = 'Mumbai Branch'
where city = 'Mumbai';
-- part E
delete from employees
where employee_id = 105;
delete from employees
where employee_name = 'Rohan Deshmukh';
delete from employees
where status = 'Inactive';
delete from employees
where salary < 30000;
delete from employees
where employee_id = 104;
-- part F
alter table employees
add column email varchar(100);
alter table employees
add column mobile varchar(15);
alter table employees
modify column city varchar(100);
alter table employees
rename column employee_name to name;
alter table employees
drop column mobile;
alter table employees
add column experience int;
update employees
set experience = 5
where employee_id = 101;
-- part G
create table departments (
department_id int primary key,
department_name varchar(100),
location varchar(100)
);
insert into departments
(department_id, department_name, location)
values
(1, 'Development', 'Pune'),(2, 'Testing', 'Mumbai'),(3, 'hr', 'Nashik');
select * from departments;
update departments
set location = 'Bangalore'
where department_id = 3;
delete from departments
where department_id = 3;
rename table departments to company_departments;
desc company_departments;
truncate table company_departments;
drop table company_departments;
show tables;