SQL Exercises
SQL Exercises
SQL DML Write an SQL query to show the second highest salary from a table.
Ans.
exercises The required query is:
Select max(Salary) from Worker where Salary not in (Select max(Salary)
from Worker);
Question 2: Write an SQL Query to find an employee whose Salary is equal or greater than
10000.
Question 3: Write an SQL Query to find name of employee whose name Start with ‘M’
For each employee, show the last name and calculate the number of months between
today and the date on which the employee was hired. Round the number of months up to
the closest whole number.
SELECT IAST_NAME, ROUND (MONTHS BETWEEN ( SYSDATE, hire_date) ) MONTHS
WORKED
FROM employees ;
SQL exercises
SQL Excersises
Write a query to get the current date.
SELECT SYSDATE();
Write a query to fetch details of employees whose EmpLname ends with an alphabet ‘A’ and
contains five alphabets.
Write an SQL query to fetch only even iDs from the table.
write a SQL query to find all those customers who does not have any grade. Return
customer_id, cust_name, city, grade, salesman_id.
SELECT * FROM customer WHERE grade IS NULL;
• write a SQL query to calculate total purchase amount of all orders.
Return total purchase amount.
SELECT SUM (purch_amt) FROM orders;
write a SQL query to find the highest grade of the customers for each
of the city. Return city, maximum grade having max grade greater
than city of code 14
SELECT city,MAX(grade)
FROM customer
GROUP BY city
Having max(grade) > (select max(grade) from customer where city=14);
• write a SQL query to find the salespersons and customers who live in
same city. Return customer name, salesperson name and salesperson
city.
Display the employee number and last name of all employees who earn
more than the average salary.
Show all employees whose salary is the same as that of employee 215
Let the user be prompted to insert a new department in the major table.
• Mark an intermediate point. Empty the entire table of customers.
Confirm that the table is empty. Commit all pending transactions.
Savepoint xyz;
Delete from customers;
Select * from customers;
Commit;