SQL Queries
SQL Queries
Write a Oracle SQL query to get the total number of employees working in the company.
Write a Oracle SQL query to get the total salary being paid to all employees.
Write a Oracle SQL query to get the maximum and minimum salary from the employees table.
Write a Oracle SQL query to display the name of the employees in order to earning from lowest salary to
highest.
Write a Oracle SQL query to display the name of the employees in order to alphabetically ascending order.
Write a Oracle SQL query to display the name and their annual salary. The result should contain those
employees first who earning the highest salary.
SELECT FIRST_NAME, LAST_NAME, SALARY*12 AS ANNUAL SALARY FROM EMPLOYEES ORDER BY ANNUAL
SALARY DESC;
Write a Oracle SQL query to display department id and total number of employees working in each
department.
...to disply only those departments where more than 5 employees are working
Write a Oracle SQL query to display the designation (job id) and total number of employees working in each
designation.
Write a query to list the name of all the employees who are working in department number 20.
Write a query to list the employees name and salary whose daily salary is more than $100.
Write a query to list the name of all the employees who are not working in department number 20.
Write a query to list the name of all the employees who are working as account manager and drawing a
salary more than $5000.
SELECT FIRST_NAME FROM employees where SALARY > 5000 AND JOB_ID = 'FI_ACCOUNT';
Write a query to list the names of all the employees who are working as accountant in finance section and
drawing a salary less than $20000.
SELECT FIRST_NAME, LAST_NAME FROM employees where SALARY < 20000 AND JOB_ID='FI_ACCOUNT';
Write a query to list the name of all the employees who are working as accountant in finance section and
drawing a salary is greater than equal to $5000 and less than equal to $20000.
SELECT FIRST_NAME, LAST_NAME FROM employees where JOB_ID='FI_ACCOUNT' AND SALARY BETWEEN
5000 AND 20000;
Write a query to list the names, salary of all the employees who are working with a commission package
Write a query to list the name, salary of all the employees where employee first name belongs in a specified
list (“Peter”, “Smith”)
Write a query to list the first name, last name, Job id of all the employees except "PRESIDENT" & "MGR" in
asc order of Salaries.
select first_name, last_name, job_id from employees where not job_id like ‘%MGR’ and not job_id like
‘%PRESIDENT’ order by salary;
Write a query to list the names (first and last) of those employees whose name starts with A
Write a query to list the names (first and last) of those employees whose name have second alphabet 's' in
their names.
Write a query to list the names (first and last) of those employees whose first name has only five characters.
select first_name, last_name from employees where length(first_name) = 5 and first_name like ‘A%’;
Write a query to list first_name, last_name of employees with the pattern 'l_x' in their first name.
Write a query to list the name (first and last name), hire date of all the employees who joined before or after
2005.
Write a query to list the names (first and last), hire date of those employees who joined in the month of
which second character is 'u'.
create table salesman(s_id number(4) not null primary key, name varchar2(15), city varchar2(15), commission
number(5,2));
name varchar2(15),
city varchar2(15),
commission number(5,2),
);
cust_name varchar2(15),
city varchar2(15),
grade number(3),
salesman_id number(4),
references salesman(salesman_id),
o_no number(5),
p_amt number(8,2),
o_date date,
customer_id number(4),
salesman_id number(4),
insert all
where a.salesman_id=b.salesman_id
and a.city=b.city;
write a SQL query to find all the customers along with the salesperson who works for them. Return
customer name, and salesperson name.
where A.salesman_id=B.salesman_id;
write a SQL query to find those sales people who generated orders for their customers but not located in the
same city. Return ord_no, cust_name, customer_id (orders table), salesman_id (orders table).
write a SQL query to find the salesperson and customer who belongs to same city. Return Salesman,
cust_name and city.
where c.city=s.city;
write a SQL query to find those orders where order amount exists between 500 and 2000. Return ord_no,
purch_amt, cust_name, city.
select o_no, p_amt, cust_name, city from customer a, orders b where a.customer_id=b.customer_id
select cust_name, a.city, name, commission from customer a, salesman b where a.salesman_id=b.sa
lesman_id;
FROM customer a
ON a.salesman_id=b.salesman_id;
write a SQL query to find those salespersons who received a commission from the company more than 12%.
Return Customer Name, customer city, Salesman, commission.
select cust_name, name, b.city, commission from customer b inner join salesman a on
a.salesman_id=b.salesman_id and commission > 0.12;
write a SQL query to find all the orders issued by the salesman 'Paul Adam'. Return ord_no, purch_amt,
ord_date, customer_id and salesman_id.
select o_no, p_amt, o_date, customer_id, salesman_id from orders where salesman_id=(select salesman_id
from salesman where name=’Paul Adam’;
write a SQL query to find all the orders, which are generated by those salespeople, who live in the city of
London.Return ord_no, purch_amt, ord_date, customer_id, salesman_id.
select o_no, p_amt, o_date, customer_id, salesman_id from orders where salesman_id=(select salesman_id
from salesman where city=’London’);
write a SQL query to find the orders generated by the salespeople who may work for customers whose id is
3007. Return ord_no, purch_amt, ord_date, customer_id, salesman_id.
write a SQL query to find the order values greater than the average order value of 10th October 2012.
Return ord_no, purch_amt, ord_date, customer_id, salesman_id.
select o_no, p_amt,o_date, customer_id, salesman_id from orders where p_amt>(select avg(p_amt) from
orders where o_date=’10-OCT-2012’);
write a SQL query to find all the orders generated in New York city. Return ord_no, purch_amt, ord_date,
customer_id and salesman_id.
Select * from orders where salesman_id=(select salesman_id from salesman where city=’New York)
write a SQL query to find all the orders generated in New York city or Paris. Return ord_no, purch_amt,
ord_date, customer_id and salesman_id.
Select * from orders where salesman_id=(select salesman_id from salesman where city=’New York’ or
city=’Paris’);
FOE VIEW CREATION
SYNTAX-
create a view for all sales person who are living in paris