Question of the Week

From today onwards I have added a new section in my blog “Question of the Week”. In this section, I will be going to ask SQL puzzle twice a week from all of you and after two days will gives the answer for that Question. So keep answering:-)

Question on 25/12/2013 :-

Suppose we have a table says tbl_students whose structure is given below:-

Create table tbl_students(Studentid int identity(1,1) , Studentname nvarchar(150))

Suppose it contains the following data:-

Read More

Answer for Question asked on 25/12/2013



Question on 28/12/2013:-

Question:- Suppose we have a table named tbl_charactername have only one column say “charactername”.
It contains 10 rows. First 5 rows contains “Vivek Johari” and the next 5 rows contains “Abhinav Golwalkar”
tbl_charactername
———————
Vivek Johari
Vivek Johari
Vivek Johari
Vivek Johari
Vivek Johari
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Abhinav Golwalkar
Now we need a SQL Query which can return the result in the form
Raad More..


Question of the Week -08/04/2014

Suppose we need to find out the name of all the months in a given year (Year will be given as an input parameter) where first day of the month falls on weekend (Saturday or Sunday). 
So what should be the query/stored procedure to get the above result?

DMCA.com

Database Consultant with more than 11.5 years of experience in database designing & programming and DBA related activities.  Had good experience on different databases like SQL Server, MySQL & Oracle, Azure SQL &  Big Data.

6 thoughts on “Question of the Week

  1. chetan Deshpande

    WITH CTE AS
    (
    SELECT 1 AS NUM UNION SELECT 3 UNION SELECT 4 UNION SELECT 8 UNION SELECT 10
    ),
    CTE1 AS
    (
    SELECT MIN(NUM) AS M,MAX(NUM) AS N FROM CTE
    UNION ALL
    SELECT M + 1,N FROM CTE1 WHERE M < N
    )
    SELECT M FROM CTE1 WHERE M NOT IN ( SELECT NUM FROM CTE )

  2. admin Post author

    Hi Chetan
    Thanks for your response.
    But your answer is not giving the correct answer as it gives 2,5,6,7,9. The correct answer is 3,5,8,9.

    Again good going..

Comments are closed.