Activity Exercise Assignment Week 10 CC105
Activity Exercise Assignment Week 10 CC105
Problems:
1. Write an SQL query to print all bonus details from the bonus table order by bonus_amount Ascending.
2. Write an sql query to fetch unique values of bonus amount from bonus table
3. Write an SQL query to print all Worker details from the Worker table order by LAST_NAME Ascending
4. Write an SQL query to print details of the Workers whose SALARY lies between 100000 and 500000
5. Write an SQL query to fetch the names of workers who earn the highest salary.
6. Prints worker details using their joining date
8. Write an SQL query to show all departments along with the number of people in there
9. Write an SQL query to show the second highest salary from a table.
10. Write an SQL query to print details of Workers with DEPARTMENT name as “Executive”.
11. Write an SQL query to fetch the count of employees working in the department ‘Executive’.
12. Write an SQL query to print the first three characters of FIRST_NAME from Worker table.
13. Write an SQL query to print the FIRST_NAME from Worker table after replacing ‘a’ with ‘A’.
14. Write an SQL query that will print all employees from the HR department ordered by first name.
15. Write an SQL query that will print all employees from the HR department ordered by last name
16. Write an SQL query that will print all employees from the HR department ordered by salary.
17. Write an SQL query that will print all bonus between 3000 and 6000
18. Write an SQL query that will print all employees with an 'M' anywhere in their first name
19. Write an SQL query that will print all unique employee titles.
20. Write a query that counts the number of workers from the worker id
C:\Users\larze>D:
D:\>cd Xammp
D:\Xammp>cd mysql\bin
D:\Xammp\mysql\bin>mysql -u root
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+--------------------+
| Database |
+--------------------+
| cc105_lab_acts |
| employees |
| information_schema |
| logistics |
| mysql |
| performance_schema |
| phpmyadmin |
| test |
+--------------------+
Database changed
MariaDB [employees]> create table worker(worker_id int(5) PRIMARY KEY, first_name varchar(20),
last_name varchar(20), salary int(15), joining_date datetime, department varchar(10);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '' at line 1
MariaDB [employees]> create table worker(worker_id int(5) PRIMARY KEY, first_name varchar(20),
last_name varchar(20), salary int(15), joining_date datetime, department varchar(10));
MariaDB [employees]> create table bonus(worker_ref_id int(5) PRIMARY KEY, bonus_date datetime,
bonus_amount int(10));
MariaDB [employees]> create table title(worker_ref_id int(5) PRIMARY KEY, worker_title varchar(15),
affected_from varchar(15));
+---------------------+
| Tables_in_employees |
+---------------------+
| bonus |
| title |
| worker |
+---------------------+
MariaDB [employees]> INSERT INTO bonus VALUES(1, '20/02/2016 0:00', '5000'), (2, '11/06/2016 0:00',
'3000'),(3, '20/02/2016 0:00', '4000'), (1, '20/06/2016 0:00', '4500'), (2, '11/12/2016 0:00', '3500');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '' at line 1
+---------------------+
| Tables_in_employees |
+---------------------+
| bonus |
| title |
| worker |
+---------------------+
(3,...' at line 2
MariaDB [employees]> INSERT INTO worker VALUES(1, 'Ryan', 'Barbacena', 100000, 20/02/2014 9:00,
'HR'),(2, 'Allea Marie', 'Royo', 80000, 11/06/2014 9:00, 'Admin'),(3, 'John Jerty', 'Pasahol', 300000,
20/02/2014 9:00, 'HR'),(4, 'Brigee Rafael', 'Tobes', 500000, 20/02/2014 9:00, 'Admin'),(5, 'Kelly',
'Mercado', 500000, 11/06/2014 9:00, 'Admin'),(6, 'Krizele Marielle', 'Aniel', 200000, 11/06/2014 9:00,
'Account'),(7, 'Johara', 'Veniegas', 75000, 20/01/2014 9:00, 'Account'),(8, 'Mae', 'Abo', 90000,
11/04/2014 9:00, 'Admin');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '9:00, 'HR'),(2, 'Allea Marie', 'Royo', 80000,
11/06/2014 9:00, 'Admin'),(3, '...' at line 1
MariaDB [employees]> INSERT INTO worker VALUES(1, 'Ryan', 'Barbacena', 100000, '20/02/2014 9:00',
'HR'),(2, 'Allea Marie', 'Royo', 80000, '11/06/2014 9:00', 'Admin'),(3, 'John Jerty', 'Pasahol', 300000,
'20/02/2014 9:00', 'HR'),(4, 'Brigee Rafael', 'Tobes', 500000, '20/02/2014 9:00', 'Admin'),(5, 'Kelly',
'Mercado', 500000, '11/06/2014 9:00', 'Admin'),(6, 'Krizele Marielle', 'Aniel', 200000, '11/06/2014 9:00',
'Account'),(7, 'Johara', 'Veniegas', 75000, '20/01/2014 9:00', 'Account'),(8, 'Mae', 'Abo', 90000,
'11/04/2014 9:00', 'Admin');
+-----------+------------------+-----------+--------+---------------------+------------+
+-----------+------------------+-----------+--------+---------------------+------------+
+-----------+------------------+-----------+--------+---------------------+------------+
MariaDB [employees]> INSERT INTO worker VALUES(1, 'Ryan', 'Barbacena', 100000, '20-02-2014 9:00',
'HR'),(2, 'Allea Marie', 'Royo', 80000, '11-06-2014 9:00', 'Admin'),(3, 'John Jerty', 'Pasahol', 300000, '20-
02-2014 9:00', 'HR'),(4, 'Brigee Rafael', 'Tobes', 500000, '20-02-2014 9:00', 'Admin'),(5, 'Kelly', 'Mercado',
500000, '11-06-2014 9:00', 'Admin'),(6, 'Krizele Marielle', 'Aniel', 200000, '11-06-2014 9:00', 'Account'),
(7, 'Johara', 'Veniegas', 75000, '20-01-2014 9:00', 'Account'),(8, 'Mae', 'Abo', 90000, '11-04-2014 9:00',
'Admin');
+-----------+------------------+-----------+--------+---------------------+------------+
+-----------+------------------+-----------+--------+---------------------+------------+
+-----------+------------------+-----------+--------+---------------------+------------+
MariaDB [employees]> INSERT INTO worker VALUES(1, 'Ryan', 'Barbacena', 100000, '2014-02-20 09:00',
'HR'),(2, 'Allea Marie', 'Royo', 80000, '2014-06-11 09:00', 'Admin'),(3, 'John Jerty', 'Pasahol', 300000,
'2014-02-20 09:00', 'HR'),(4, 'Brigee Rafael', 'Tobes', 500000, '2014-02-20 09:00', 'Admin'),(5, 'Kelly',
'Mercado', 500000, '2014-06-11 09:00', 'Admin'),(6, 'Krizele Marielle', 'Aniel', 200000, '2014-06-20
09:00', 'Account'),(7, 'Johara', 'Veniegas', 75000, '2014-01-20 09:00', 'Account'),(8, 'Mae', 'Abo', 90000,
'2014-04-11 09:00', 'Admin');
+-----------+------------------+-----------+--------+---------------------+------------+
+-----------+------------------+-----------+--------+---------------------+------------+
MariaDB [employees]> INSERT INTO bonus VALUES(1, '2016-02-20 00:00', '5000'),(2, '2016-06-11 00:00',
'3000'),(3, '2016-02-20 00:00', '4000'),(1, '2016-06-20 00:00', '4500'),(2, '2016-12-11 00:00', '3500');
+---------------+---------------------+--------------+
+---------------+---------------------+--------------+
+---------------+---------------------+--------------+
MariaDB [employees]> INSERT INTO title VALUES(1, 'Manager', '2016-02-20 00:00'),(2, 'Executive',
'2016-06-11 00:00'),(8, 'Executive', '2016-06-11 00:00'),(5, 'Manager', '2016-06-11 00:00'),(4, 'Asst.
Manager', '2016-06-11 00:00'),(7, 'Executive', '2016-06-11 00:00'),(6, 'Lead', '2016-06-11 00:00'),(3,
'Lead', '2016-06-11 00:00');
+---------------+---------------+-----------------+
+---------------+---------------+-----------------+
MariaDB [employees]>