SQL Questions.
SQL Questions.
SQL Questions.
Operators in SQL:
Arithmetic Operator
Operator Symbol Operation
+ Addition
- Subtraction
* Multiplication
/ Division
Mod Remainder
Comparison/Relational Operator
Operator Symbol Operation
= Equal to
Logical Operator
Operator Symbol Operation
OR Or Logical Operator
9. WAQ to display all records of those employee who job_id 10 or salary equal to
20000.
10. WAQ to display all records of those employee who salary between 10000 and
20000.
Select * from employees where Salary >=10000 and salary <= 20000;
Or
11. WAQ to display all records of those employee who salary not between 10000
and 20000 and job_id= Programmer
Select * from employees where Salary <10000 and salary > 20000 and
job_id=’Programmer’;
Or
Select * from employees where Salary not between 10000 and 20000 and
job_id=’Programmer’;
14. WAQ to display all records of those employee who working in department 10,
20 and 30.
Select * from employees where department_id=10 or department_id=20 or
department_id=30.
Or
Select * from employees where department_id in (10,20,30)
15. WAQ to display employee_id, email, salary, job_id of those employee who
working as faculty and clerk and salary greater than equal to 12000.
Syntax:
<Column Name> in(value1, value2,…….)
16. WAQ to display all records of those employee who working as programmer
and analyst and department 10 and 20 and hire_date from 20-Aug-2018 to
19- AUG- 2021.
select * from employees where job_id in(‘Programmer’, ‘Analyst’) and
department_id in(10,20) and hire_date between ‘20-AUG-2018’ and ‘19-AUG-
2021’
Like Operator: It is used extract pattern based record from table. It match any
given character or set of characters form existing table record and gives result.
Syntax:
<Column name> like ‘_/%<pattern character>_/%’
17. WAQ to display all records of those employee whose first_name started from
A character.
Select * from employees where first_name like ‘A%’
18. WAQ to display all records of those employee whose first_name last character
is r.
19. WAQ to display all records of those employee whose first_name second
character is a and last_name second last character is i.
Select * from employees where FIRST_NAME like '_a%' and LAST_NAME like
'%i_' ;
20. WAQ to display employee_id, first_name as name and salary increased by 10%
as Increased salary of those employee whose first_name third last character is
p and getting salary 10000, 20000 and 30000.
Select employee_id, first_name “Name”, Salary+Salary*10/100 “Increase
Salary” from employees where first_name like ‘%p_ _’ and salary in(10000,
20000, 30000)
Is Null: - This operator is used find those records which are empty.
Syntax: -
<Column name> is null
21. WAQ to display all records of those employee whose department id is blank.
22. WAQ to display all records of those employee whose first_name not started
with A letter and salary is not mentioned.
Select * from employees where First_name not like 'A%' and salary is null;
Is Not Null : It negates is null value.
Distinct:- This keyword is used to show only unique value of any column.
ORDER BY Clause: -
Syntax: -
Order by <Column name>/<column position in query> ASC / DESC
Note: ASC is optional.
25. WAQ to display all records in ascending order using salary column.
30. WAQ to display total amount of salary who working as programmer and
department 10 and 30.
31. WAQ to display average salary and total salary of those employee who working
as Programmer and hire_date from 01-01-20218 to 02-01-2020.
34. WAQ to display all records of those employee who getting maximum salary.
Select * from employees where salary=24000
Group By Clause
35. WAQ to display total salary of each department.
Select sum(salary) from employees group by department_id;
36. WAQ to display each post total number of employee and maximum salary.
HAVING Clause :
The SQL HAVING clause is used in combination with the GROUP BY clause to restrict
the groups of returned rows to only those whose the condition is TRUE. The
HAVING clause was added to SQL because the WHERE keyword could not be used
with aggregate functions column. The HAVING clause must follow the GROUP BY
clause in a query and must also precedes the ORDER BY clause if used.
Syntax:-
Having <aggregate function column> operator value;
38. WAQ to display those department which have 5 IT_PROG.
40. WAQ to display all record of those employee whose salary is equal to
employee_id 105’s salary.
Select * from employee where salary= (Select salary from employees where
employee_id=105);
41. WAQ to display all records of those employees who getting maximum salary.
Select * from employees where salary = (select max (salary ) from employees)
42. WAQ to display employee_id, first_name and salary of those employees who
getting minimum salary and working IT_PROG.