SQL Interview Questions | Page 3


Question 21:

How can I retrive all records of Emp those are not present in Emp1?

SELECT * FROM HR.EMP
EXCEPT
SELECT * FROM HR.EMP1
Question 22:

Find all Employee records containing the word "mit" in name and which is case insensitive.

SELECT * 
FROM HR.EMP 
WHERE UPPER(NAME) LIKE '%JOH%'
Question 23:

Write an SQL Query to find name of employee whose name Start with ‘A’

SELECT * 
FROM HR.EMP 
WHERE NAME like 'J%';
Question 24:

Write an SQL Query to find name of employee whose name has second character ‘A’

SELECT * 
FROM HR.EMP 
WHERE NAME like '_A%';
Question 25:

Write a SQL Query to select employees having salary greater than 10000 and less than 20000

SELECT *
FROM HR.EMP 
WHERE SALARY BETWEEN 10000 AND 50000

Question 26:

Write a SQL Query to find  day from given date?

SELECT DAY(GETDATE()) as 'Day';
Question 27:

Write a SQL Query to find  month from given date?

SELECT MONTH(GETDATE()) as 'Month';
Question 28:

Write a SQL Query to find  year from given date?

SELECT YEAR(GETDATE()) as 'Year';
Question 29:

For a given table find the sum of salary based on age.

Id Salary Age Department
1 10000 34 IT
2 50000 35 Network
3 40000 43 Finance
4 20000 35 Admin
5 1000 35 IT

We can use SUM() aggregate function to calculate the sum of salary by Age. So we can write below query to get the sum of salaries by age group.

Query

SELECT Age, SUM(Salary) AS TotalSalary 
FROM dbo.Employees
GROUP BY Age

Result

Age TotalSalary
34 10000
35 71000
43 40000

For more details and example on SUM function refer SUM() function.

Share interview questions

Comments

Comments
comments powered by Disqus

Navigation

Social Media