Experiment No.
Aim: To study and implement queries in RDBMS using in built functions
Part A:
Theory: RDBMS stands for Relational Database Management System. RDBMS is the basis for SQL,
and for all modern database systems like MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft
Access.
A Relational database management system (RDBMS) is a database management system
(DBMS) that is based on the relational model. The data in RDBMS is stored in database objects
called tables. The table is a collection of related data entries and it consists of columns and rows. The
data in RDBMS is stored in database objects called tables. A table is a collection of related data
entries and it consists of columns and rows. The following are the queries in RDBMS:
SELECT:
SQL SELECT statement is used to fetch the data from a database table which returns data in
the form of result table. These result tables are called result-sets.
The basic syntax of SELECT statement is as follows:
SELECT column1, column2, columnN FROM table_name;
Here, column1, column2...are the fields of a table whose values you want to fetch. To fetch all the
fields available in the field, the following syntax can be used:
SELECT * FROM table_name;
WHERE:
The SQL WHERE clause is used to specify a condition while fetching the data from single
table or joining with multiple tables.
If the given condition is satisfied then only it returns specific value from the table. You would
use WHERE clause to filter the records and fetching only necessary records.
The WHERE clause is not only used in SELECT statement, but it is also used in UPDATE,
DELETE statement, etc., which we would examine in subsequent chapters.
The basic syntax of SELECT statement with WHERE clause is as follows:
SELECT column1, column2, columnN
FROM table_name
WHERE [condition]
ORDER BY:
The SQL ORDER BY clause is used to sort the data in ascending or descending order, based
on one or more columns. Some database sorts query results in ascending order by default.
The basic syntax of ORDER BY clause is as follows:
SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;
GROUP BY:
The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange
identical data into groups.
The GROUP BY clause follows the WHERE clause in a SELECT statement and precedes
the ORDER BY clause.
The basic syntax of GROUP BY clause is given below. The GROUP BY clause must follow
the conditions in the WHERE clause and must precede the ORDER BY clause if one is used.
SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2
Part B:
1. Show all the data of the clerks who have been hired after the year 1997
2. Show the last name, job, salary and commission of those employees who earn commission.
Sort the data by salary in descending order
3. Show name, salary, commission, job of employees that have no commission with a 10% raise
in the salary (round off salaries)
4. Show the last names of all employees together with the number of years and number of
completes months that they have been employed
5. Show those employees that have a name starting with J, K, L , or M
6. Show name, salary of all employees, and indicate with “Yes” or “No” whether they receive a
commission
7. Show the department names, locations(city), Names, Job titles and salaries of employees who
work in location 1800
8. How many employees have name that ends with an n? Create two possible solutions
9. Show the names and locations for all departments and the number of employees working in
each department. Make sure that department without employees are included as well.
10. Which jobs are found in departments 10 and 90?
11. Which jobs are found in the Administration and Executive departments and how many
employees do these jobs? Show the job with highest frequency first
12. Show all employees who were hired in the first half of the month (before 16th of the month)
13. Show the names, Salaries and number of Dollars (in thousands) that all employees earn
14. Show the department number and lowest salary of the departments with highest average
salary.
Output: Screen shot of each query+ Output