Top 100 sql server queries interview questions


SQL Server Advanced Questions - 'Top, Union, admission fees and Group by' questions


43) Select TOP Nth (any number) admission fees from tblStudent table
1
select top 1 * from tblStudent
44) Select second highest admission fees from "tblStudent" table.
1
2
Select TOP 1 Admission_fee from (Select TOP 2 Admission_fee from tblStudent
order by Admission_fee DESC) T Order By Admission_fee ASC
45) Select TOP 2 Admission fees from tblStudent table
1
select top 2 * from tblStudent order by Admission_fee desc
46) Select Highest Admission fees from tblStudent table.
1
Select Max(Admission_fee) from (select top 6 * from tblStudent) A
47) Select Minimum Admission fees from tblStudent table.
1
Select Min(Admission_fee) from (select top 6 * from tblStudent) A
48) Select FirstName, LastName from tblStudent table in singal column.
1
select FirstName from tblStudent union select LastName from tblStudent
49) Get students details from "tblStudent" table whose admission fees is less than 15000.
1
Select * from tblStudent where Admission_fee < 15000
50) Get students details from "tblStudent" table whose admission fees is greater than 15000.
1
Select * from tblStudent where Admission_fee > 15000
51) Get students details from "tblStudent" table whose admission fees in between 10000 and 15000.
1
Select * from tblStudent where Admission_fee between 10000 and 15000
52) Select 5 % of admission fees from sara , 10% of admission fees from Dora and for other 15 % of admission fees as 'Deducted_Admission_fee' from tblStudent table.
1
2
SELECT FirstName, CASE FirstName WHEN 'Sara' THEN Admission_fee * .10 WHEN 'Dora' THEN Admission_fee * .15 ELSE Admission_fee * .15
 END "Deducted_Admission_fee" FROM tblStudent
53) Write a query to get how many students exist in tblstudent.
1
select COUNT(*) from tblStudent
54) Write the query to get the branch and branch wise total(sum) admission fees, display it in ascending order according to admission fees.
1
2
Select Branch, SUM(admission_fee) as Total_admission_fees from tblStudent
group by Branch order by SUM(admission_fee) ASC
55) Write the query to get the branch and branch wise total(sum) admission fees, display it in desending order according to admission fees.
1
2
Select Branch, SUM(admission_fee) as Total_admission_fees from tblStudent
group by Branch order by SUM(admission_fee) DESC
56) Get branch wise average admission fees from "tblStudent" table order by admission fees ascending order.
1
2
Select Branch, AVG(admission_fee) as Average_admission_fees from tblStudent
group by Branch order by SUM(admission_fee) ASC
57) Get branch wise maximum admission fees from "tblStudent" table order by admission fees descending order.
1
2
Select Branch, MAX(admission_fee) as Maxmum_admission_fees from tblStudent
group by Branch order by SUM(admission_fee) DESC
58) Get branch wise minimum admission fees from "tblStudent" table order by admission fees ascending order.
1
2
Select Branch, MIN(admission_fee) as Minimum_admission_fees from tblStudent
group by Branch order by SUM(admission_fee) ASC
59) Get branch, no of students in a branch, total admission fees with respect to a branch from tblStudent table order by admission fees descending.
1
2
Select Branch,count(FirstName),sum(admission_fee) Admission_fee from tblStudent
group by Branch order by Admission_fee desc
60) Select no of students joined with respect to year and month from tblStudent table.
1
2
select datepart (YYYY,Admission_date) Admission_year,datepart (MM,Admission_date) Admission_month,
count(*) Total_student from tblStudent group by datepart(YYYY,Admission_date), datepart(MM,Admission_date)
« 1 2 3 4 5 6 »  

Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.