Structured Query Commands
Structured Query Commands
No19
DATE:
SQL COMMANDS EXERCISE – 1
(Basic Queries – I)
AIM:
To write Queries for the following Questions based on the given table:
USE EMPS;
27
(e) Write a Query to List all the tables that exists in the current database.
SHOW TABLES;
Output:
(f) Write a Query to insert all the rows of above table into Info table.
(g) Write a Query to display all the details of the Employees from the above table 'INFO'.
Output:
****************************************************************************************************
28
Ex.No: 20
DATE:
(a) Write a Query to Display Employees’ name and City from the above table.
Output:
(b) Write a Query to Display all details of Employees who are living in Chennai.
Output:
29
(c) Write a Query to get the name and salary of the employee whose salary is above
15000 and gender is not male.
(d) Write a query to update increase 10% Salary of an employee whose City is 'CHENNAI'
and Gender is 'MALE'.
*************************************************************************
30
Ex.No: 21
DATE:
SQL COMMANDS EXERCISE – 3
(Aggregate Functions, Order By Group By, Havning
Clause)
AIM:
To write Queries for the following Questions based on the given table:
EmpID Name Gender Age Dept DOJ Salary City
1 Praveen M 25 Sales 1989-06-08 20000 Chennai
2 Arun M 29 Marketing 1989-09-26 22000 Chennai
3 Usha F 27 Finance 1994-08-09 25000 Bangalore
4 Bala M 31 Sales 1990-03-23 27000 NULL
5 Rani F 28 Marketing 1990-04-23 27000 Mumbai
6 Nisha F 26 NULL 1991-02-24 18000 Bangalore
7 Manoj M 32 Finance 1982-05-06 30000 Goa
(a) Write a Query to list names of Employees in Descending order.
Output:
Output:
(c) Write a Query to display maximum salary and minimum salary of employees.
SELECT MAX(SALARY), MIN(SALARY) FROM INFO;
Output:
31
(d) Write a Query to count the number of employees earning more than 25000.
(e) Write a query to display sum of salary of the employees grouped by department wise.
(f) Write a query to display the department names where number of employees are
greater than or equal to 2.
Output:
****************************************************************************************
32
Ex.No: 22
DATE:
SQL COMMANDS EXERCISE – 4
(Mathematical Functions)
AIM:
To write Queries for the following Questions based on the given table -"STU":
(a) Write a Query to Display square of age that got admission in the month of August.
Output:
33
(c) Write a Query to display Student names and their Percentage in round figure.
Output:
(d) Display Name, Percentage and round up the remainder marks up to 2 decimal
places.
Output:
**************************************************************************************
34
Ex.No: 23
DATE:
Output:
(b) Write a Query to display department name and its respective number of characters
in Dept column.
Output:
35
(c) Write a Query to display first 2 characters of the column Name.
Output:
(e) Write a query to display the names of all students and extract five characters from
the third position of the 'Name' field.
Output:
**********************************************************************************************
36
Ex.No: 24
DATE:
(a) Write a Query to display student name and month of date of admission of all
students.
(b) Write a Query to display Student name and day name of the students’ DOA of the
table STU.
Output:
37
(c) Write a query to display the joining year of IP students.
SELECT YEAR(DOA) FROM STU WHERE DEPT='IP'
Output:
(d) Write a Query to Display the month for the date_of_birth of all students.
Output:
(e) Write a query to display the names of the students who joined in the month of June.
*********************************************************************************************
38