Advertisements

SQL SERVER Puzzles / SQL Puzzles / T-SQL Puzzles


WELCOME TO THE WORLD OF T-SQL PUZZLES / CHALLENGES

List of T SQL Interview puzzles

Here I come with cunning SQL Queries / Puzzles which are frequently asked in SQL / Database / MSBI / SQL BI interviews from developer to Architect level. All the questions below seems easy but it would be complex situation when you face these query in Interview time.

If you have any puzzle in mind or if you want me to solve some puzzle or if you have difficulty in solving business problem please email me @ pawankkmr@gmail.com. I would be happy to help.

This would be best for you to go through following Interview questions / puzzles before attend any technical interview. 

Please visit Interview Puzzles – Finding Outputs section where we have to provide the output based on the query written by the Interviewer.

Sr No SQL Server Puzzle
310
SQL Puzzle | SQL Puzzle | SQL Puzzle | Fetch duplicate data ( The 5 Minutes Puzzle )
309
SQL Puzzle | SQL Puzzle | The Seller Puzzle
308
SQL Puzzle | SQL Puzzle | Strip HTML Characters from a string column in SQL Server
307
SQL Puzzle | The String format Puzzle (INT.INT.INT)
306
SQL Puzzle | Extract Integer Present at the start of the string in a column
305
SQL Puzzle | The Quantity SUM Sales Puzzle
304
SQL Puzzle | The PIVOT Puzzle – VI ( Is Data Present for Id – Y/ Blank )
303 SQL Puzzle | The Header and Detailed Data Puzzle
302 SQL Puzzle | The Count Puzzle
301 SQL Puzzle | The Weird String Puzzle
300 SQL Puzzle | Find Length of longest value from columns in all tables from a database
299 SQL Puzzle | The Complex Hierarchy Puzzle [All Positions below – Line Manager]
298 SQL Puzzle | The BCP OUT with Field Headers Puzzle
297 SQL Puzzle | The Additional Quantity Puzzle
296 SQL Puzzle | Average Time Puzzle
295 SQL Puzzle | The 3 Integers with 2 Dots Puzzle
294 SQL Puzzle | Get Previous and Next Value Puzzle
293 SQL Puzzle | The Next Working Date Puzzle
292 SQL Puzzle | Search Only NVARCHAR Values Puzzle
291 SQL Puzzle | The XML Node Copy Puzzle
290 SQL Puzzle | The Overlapping Dates Puzzle
289 SQL Puzzle | The Non Space Puzzle
288 SQL Puzzle | The XML Explicit Puzzle
287 SQL Puzzle | The 3 Decimal Digits Puzzle
286 SQL Puzzle | The Percentage Puzzle
285 SQL Puzzle | The OrdersAndState puzzle
284 SQL Puzzle | The Merge Puzzle
283 SQL Puzzle | Get DB Name,LogFile Size, MDB File Size and Owner from System Tables
282 SQL Puzzle | The Duplicate diagnosis Puzzle
281 SQL Puzzle | The Date Format (yyyy-MM-dd hh:mm:ss) Puzzle
280 SQL Puzzle | The Address puzzle
279 SQL Puzzle | Phone formatting puzzle
278 SQL Puzzle | Eliminate starting comma(s) and ending comma(s) from a string using Select
277 SQL Puzzle | Time spent by employee in a site
276 SQL Puzzle | The Separation (Chr & Int) Puzzle
275 SQL Puzzle | The Two Underscore Puzzle
274 SQL Puzzle | The Published Post Puzzle
273 SQL Puzzle | The Completed Part Puzzle
272 SQL Puzzle | The Distinct Records Multi-Col Puzzle
271 SQL Puzzle | The Min Max Puzzle
270 SQL Puzzle | The Row Number Puzzle
269 SQL Puzzle | The Phone Number Puzzle
268 SQL Puzzle | The Nbr(Range) Puzzle
267 SQL Puzzle | Find max except negative values
266 SQL Puzzle | Remove Words from a string(column) present in a table
265 SQL Puzzle | Find Grand Parent, Parent and Child Puzzle ( Parent/Child Relationships )
264 SQL Puzzle | The Not Between Puzzle
263
SQL Puzzle | Find Grand Parent, Parent and Child Puzzle ( Parent/Child Relationships )
262 SQL Puzzle | The Ntext Column Problem
261 SQL Puzzle | Append 0 to month if month is < 10(Trick)
260 SQL Puzzle | Get Count of Values from Multiple Columns and Rows
259 SQL Puzzle | Get Count and Numbers Puzzle
258 SQL Puzzle | Find First and Last day of Current Month for Last Year from Current Date
257 SQL Puzzle | The Primary Key Puzzle
256 SQL Puzzle | The nearest date puzzle
255 SQL Puzzle | SELECT Columns which doesn’t have all zero value – II
254 SQL Puzzle | The Varchar column and comma Puzzle
253 SQL Puzzle | The ISNULL Puzzle
252 SQL Puzzle | Create constraint on multiple columns
251 SQL Puzzle | Delete Duplicate Records from a Table but one
250 SQL Puzzle | The Hotel Puzzle
249 SQL Puzzle | The Pivot Puzzle – VII
248 SQL Puzzle | SELECT Columns which doesn’t have all zero value
247 SQL Puzzle | Order By using Parent Child Relationship
246 SQL Puzzle | How to transfer logins and passwords between instances of SQL Server
245 SSAS | Find users who are connected to the SSAS Cube
244 SQL Puzzle | How to Remove Huge Multiple Spaces from a Varchar Field
243 SQL Puzzle | How to move database from one drive to another
242 SQL Puzzle | Order By using Parent Child Relationship
241 SQL Puzzle | Highest and lowest value rows alternatively in SQL Server
240 SQL Puzzle | The Case & Between Puzzle
239 SQL Puzzle | The String Puzzle [Split Puzzle]
238 SQL Puzzle | How to get List of Connections, Username and Database Name on a Server
237 SQL Puzzle | How to get List of Stored Procedures along with the table & column names for all DBs on a SERVER
236 SQL Puzzle | How to get List of Stored Procedures along with the table names in a DB
235 SQL Puzzle | The Updated By Puzzle – I
234 SQL Puzzle | The Updated By Puzzle
233 SQL Puzzle | Get Duplicate Rows from Multiple Columns
232 SQL Puzzle | Script to get growth of the databases size over a given period
231 SQL Puzzle | List of foreign keys with their tables in SQL Server
230 SQL Puzzle | The Late Tolerance Puzzle
229 SQL Puzzle | The Separation Puzzle – 1
228 SQL Puzzle | No of Active Users at each time in the System
227 SQL Puzzle | Update Data that with a string contains apostrophe
226 SQL Puzzle | The XML Path Puzzle
225 SQL Puzzle | First and Second Record – Pivot Format
224 SQL Puzzle | The A & B Puzzle
223 SQL Puzzle | Working Hours Puzzle
222 SQL Puzzle | Remove Duplicate Ints From String Puzzle
221 SQL Puzzle | The Status Puzzle
220 SQL Puzzle | How to Kill all other existing SQL server connection except the login started by current session
219 SQL Puzzle | How to Count total number of Rows in all databases on a Server
218 SQL Puzzle | Remove Duplicate Word(s) from the String/Sentence
217 SQL Puzzle | The Phone Call Puzzle
216 SQL Puzzle | The Greatest Number of Employees (Solution Time:))
215 SQL Puzzle | The Longest Period – II [ SQL Query to Calculate the longest period ( in days ) that the company has gone without hiring or firing any one ] (Solution Time :))
214 SQL Puzzle | The Date Puzzle – II (Solution Time :))
213 SQL Puzzle | 2 Digit Puzzle [No Reverse Function] (Solution Time :))
212 SQL Puzzle | The Date Puzzle – 1
211 SQL Puzzle | Matches won & lost by Each team [Asia Cup Puzzle – II] (Solution Time 🙂 )
210-1 SQL Puzzle | The Asia Cup Puzzle [Solution Time :)]
210 SQL Puzzle | The Event Puzzle
209 SQL Puzzle | The Keys Puzzle
208 SQL Puzzle | The Sum Puzzle – V
207 SQL Puzzle | The Sum Puzzle – VI
206 SQL Puzzle | The Product’s Latest Version Puzzle
205 SQL Puzzle | All values = Val1 Puzzle
204 SQL Puzzle | The Pivot Puzzle – V
203 SQL Puzzle | The Manager & Manager’s Manager Puzzle
202 SQL Puzzle | The Five Consecutive Dates Puzzle
201 SQL Puzzle | The Order By Puzzle
200 SQL Puzzle | Update one table and Insert in another table using single T-SQL statement at same time (Multiple Solutions :))
199 SQL Puzzle | Get File Size using T-SQL
198 SQL Puzzle | The Maximum characters matching in a string Puzzle
197 SQL Puzzle | Remove NULLs via row-wise pattern
196 SQL Puzzle | Sum of Positive, Negative, Total Sum & Sum ignoring -ve values in a single Query
195 SQL Puzzle | Ignore zeros till you get the first non zero value
194 SQL Puzzle | The Ids Puzzle
193 SQL Puzzle | The Header and Footer Puzzle [Difficult Challenge]
192 SQL Puzzle | The Cast Puzzle [Minimum Changes]
191 SQL Puzzle | Getting group by sum with Total Sum in a Single Query [ Multiple Solutions ]
190 SQL Puzzle | Getting sum of current value, previous value and next value in a single query
189 SQL Puzzle | Getting group by sum and total sum in a single query [with Multiple Solutions – Best One]
188 SQL Puzzle | The Replace Puzzle ( Excellent Challenge )
187 SQL Puzzle | Search Phone Number Puzzle (Escape Multiple Characters)
186 SQL Puzzle | Fill the Date Gaps Puzzle (No tally or numbers table)
185 SQL Puzzle | Get # of Hits Per Hour
184 SQL Puzzle | The Missing Gaps Puzzle [Multiple Solutions – Best One]
183 SQL Puzzle | Week on Week sales % Puzzle
182 SQL Puzzle | The Pivot Puzzle [Multiple Solutions – Best One]
181 SQL Puzzle | Delete Duplicate Records using Outer Join
180 SQL Puzzle | Count & Filter Puzzle
179 SQL Puzzle | Word Search Puzzle
178 SQL Puzzle | The Join Puzzle
177 SQL Puzzle | Hiring Years Puzzle
176 SQL Puzzle | No Hiring Years Puzzle
175 SQL Puzzle | How to get Date Part & Time Part only from DateTime in Sql Server [Multiple Methods]
174 SQL Puzzle | Make all UPPER/LOWER case of string to Proper Case/Title Case [Multiple Methods]
173 SQL Puzzle | The Salary Share Puzzle
172 SQL Puzzle | Biggest Prime Number Divisor of an Input Number
171 SQL Puzzle | The String Puzzle – Combine data by one column and then another one using comma
170 SQL Puzzle | Counting occurrences of a substring within a string
169 SQL Puzzle | Generate Numbers – Quickly
168 SQL Puzzle | The Prime Number Puzzle – V
167 SQL Puzzle | The Name Puzzle
166 SQL Puzzle | Generate IDs Puzzle
165 SQL Puzzle | REVERSE a String Without Using Reverse Function / Recursive CTE / While Loop
164 SQL Puzzle | The ASCII Puzzle – II
163 SQL Puzzle | The Consecutive Groups Count Puzzle
162 SQL Puzzle | The Maximum Count of Consecutive Numbers Puzzle
161 SQL Puzzle | Delete Duplicate data from table without using Aggregate & Ranking functions
160 SQL Puzzle | The Separation Puzzle
159 SQL Puzzle | Break Table in Equal Parts
158 SQL Puzzle | Generate Fibonacci Series in SQL Server
157 SQL Puzzle | Fetch 2 records from each salary bracket
156 SQL Puzzle | 5 Prime Numbers above a given number
155 SQL Puzzle | The Maximum Repetition Puzzle
154 SQL Puzzle | Multi Column Pivot Puzzle ( Gmail )
153 SQL Puzzle | Find Strings that contains % Character
152 SQL Puzzle | The Circular Prime Numbers Puzzle
151 SQL Puzzle | Generate Possible combinations of a number puzzle
150 SQL Puzzle | The NULL Columns Puzzle
149 SQL Puzzle | Inserted Rows Count Puzzle
148 SQL Puzzle | Check input parameter value is integer or not – Inbuilt function & Custom Logic
147 SQL Puzzle | Even Odd Count Puzzle
146 SQL Puzzle | Calculate 2nd Highest & 2nd Lowest Salary / Nth Highest and Nth Lowest Salary at the same time
145 SQL Puzzle | The Count different type of characters from a string Puzzle
144 SQL Puzzle | The Multiple Sums Puzzle
143 SQL Puzzle | Get Last 4 Characters from a String without Left & Right Function
142 SQL Puzzle | Generate Random Numbers Within Limits Puzzle
141 SQL Puzzle | The Replace Puzzle
140 SQL Puzzle | The In NotIn Puzzle
139 SQL Puzzle | Multiple Column Pivoting Puzzle
138 SQL Puzzle | Single Query Multiple Condition Puzzle
137 SQL Puzzle | The Fiscal Puzzle – II
136 SQL Puzzle | The Single Update Statement Puzzle
135 SQL Puzzle | Generate Multiple Years Puzzle
134 SQL Puzzle | The Remove NULL Puzzle
133 SQL Puzzle | The Sum of Previous Value to Current Value Puzzle
132 SQL Puzzle | Facebook Puzzle – Count Characters in a string
131 SQL Puzzle | Facebook Puzzle – 1
130 SQL Puzzle | The Yes No Puzzle
129 SQL Puzzle | The Numbers Duplicate Puzzle
128 SQL Puzzle | The SUM Puzzle
127 SQL Puzzle | The Remove duplicate UOM Puzzle
126 SQL Puzzle | Replace Comma Seperated Ids with their Names Puzzle
125 SQL Puzzle | The Fiscal Puzzle
124 SQL Puzzle | The Make Zero Puzzle
123 SQL Puzzle | The User Access Control Puzzle
122 SQL Puzzle | The Max First Rank Puzzle
121 SQL Puzzle | The Comma Separated Puzzle – VI
120 SQL Puzzle | Find Different Values Puzzle
119 SQL Puzzle | Get Weeks (Start Date – End Date) for a Month & Year
118 SQL Puzzle | 2nd Highest Salary in Each Department using OffSet & Fetch Method
117 SQL Puzzle | T-SQL Query Problem
116 SQL Puzzle | The Time Difference Puzzle
115 SQL Puzzle | Check Prime Number Puzzle
114 SQL Puzzle | The Middle 4 Puzzle
113 SQL Puzzle | The Prime Numbers Puzzle
112 SQL Puzzle | Find Square Numbers from Numbers Table Puzzle
111 SQL Puzzle | Split & Count Puzzle
110 SQL Puzzle | The Pattern Puzzle #2 ( Fun with SQL )
109 SQL Puzzle | Simple Pivot – Facebook Puzzle
108 SQL Puzzle | Find every Saturday and their corresponding last months Saturday with in a Year
107 SQL Puzzle | Find every 3rd Tuesday in each month with in a Year
106 SQL Puzzle | Star Pattern Puzzle ( Fun with SQL )
107 SQL Puzzle | Sort Data by Version Puzzle
105 SQL Puzzle | Find Numbers that satisfies | Number – ReverseDIGITS(Number) = SUMOfDIGITS(Number) + MULTIPLICATIONOFDIGITS(Number)
104 SQL Puzzle | Multiplication of Digits Puzzle
103 SQL Puzzle | Sum of Digits Puzzle
102 SQL Puzzle | Convert a string into a table n number of times ( n = length of the string )
101 SQL Puzzle | Convert a string into a table without any delimiter
100 SQL Puzzle | Split String Puzzle – II (Linked In)
99 SQL Puzzle | Second Highest Salary Puzzle – Different Methods & the Best Method
98 SQL Puzzle | Replace 6 or more Consecutive Digits with x from a string Puzzle
97 SQL Puzzle | Records not ending with a character Puzzle – BEST Approach
96 SQL Puzzle | Pivoting Data Puzzle
95 SQL Puzzle | The Remove Nulls Puzzle
94 SQL Puzzle | Minus -1 or Minimum Child Puzzle
93 SQL Puzzle | The Gap Puzzle Puzzle – III
92 SQL Puzzle | The Total Values Missing Puzzle
91 SQL Puzzle | The Gap Puzzle Puzzle – II
90 SQL Puzzle | The FizzBuzz Puzzle
89 SQL Puzzle | Change 0 to 1 and 1 to 0 Puzzle
87 SQL Puzzle | The Tree Puzzle
86 SQL Puzzle | The Previous Value(Non-Null) Puzzle
85 SQL Puzzle | The Median Puzzle
84 SQL Puzzle | The Average Marks Puzzle
83 SQL Puzzle | The Passengers in the Bus Puzzle
82 SQL Puzzle | The Gap Puzzle
81 SQL Puzzle | The Complex Week Puzzle
80 SQL Puzzle | The Grouping Puzzle
79 SQL Puzzle | The Consecutive Wins Puzzle 2
78 SQL Puzzle | The ZIP Grouping Puzzle
77 SQL Puzzle | The Multiple Join Single Query Puzzle
76 SQL Puzzle | The Bitwise Puzzle 
75 SQL Puzzle | The Overlapping Dates Puzzle 
74 SQL Puzzle | The Non Zero Puzzle 
73 SQL Puzzle | The Graph Shortest Path Puzzle 
72 SQL Puzzle | The ASCII Puzzle 
71 SQL Puzzle | The Perfect Number Puzzle 
70 SQL Puzzle | The Complex Time Puzzle 
69 SQL Puzzle | The Multiple Condition Puzzle 
68 SQL Puzzle | The Wild Card Puzzle 
67 SQL Puzzle | The Missing Numbers Puzzle 
66 SQL Puzzle | Distinct A,B,C Puzzle 
65 SQL Puzzle | Multiple Ways to Split a String Puzzle
64 SQL Puzzle | How Many Work/Week Days In Date Range Puzzle
63 SQL Puzzle | The Join and the Aggregate Puzzle
62 SQL Puzzle | AIRPLANES AND PILOTS Puzzle
61 SQL Puzzle | Swap Values of a Column Puzzle
60 SQL Puzzle | Find 2nd highest Salary using Top Clause Puzzle
59 SQL Puzzle | The Student and the Marks Puzzle
58 SQL Puzzle | Count NULL Values Puzzle
57 SQL Puzzle | Count Spaces in a string Puzzle
56 SQL Puzzle | The Training Puzzle 
55 SQL Puzzle | The Missing Gaps Puzzle 
54 SQL Puzzle | The Max Puzzle 
53 SQL Puzzle | The Missing Numbers Puzzle 
52 SQL Puzzle | Complete the Sequence Puzzle 
51 SQL Puzzle | The Send & Ack Puzzle 
50 SQL Puzzle | Matching data between rows and columns Puzzle
49 SQL Puzzle | The Sequencer Puzzle 
48 SQL Puzzle | The Manage and Employee Puzzle – 2
47 SQL Puzzle | The Sorting(Horizontal & Verticle) Puzzle
46 SQL Puzzle | The Version Puzzle
45 SQL Puzzle | The Range Puzzle
44 SQL Puzzle | All Items Puzzle
43 SQL Puzzle | All Products Puzzle
42 SQL Puzzle | Group By – Remove NULL UOM Puzzle
41 SQL Puzzle | The Deal Puzzle
40 SQL Puzzle | The Manager Employee Hierarchy Puzzle
39 SQL Puzzle | The Male and Female Count Puzzle
38 SQL Puzzle | The Friday Salary Puzzle
37 SQL Puzzle | Fruit Count Puzzle
36 SQL Puzzle | Year & Month wise data – The Pivot Puzzle
35 SQL Puzzle | The Case Replace Puzzle
34 SQL Puzzle | The Candidate Joining Problem
33 SQL Puzzle | Find Duplicate Puzzle
32 SQL Puzzle | The Ticket Approver Puzzle
31 SQL Puzzle | The Running Balance Puzzle
30 SQL Puzzle | The Patient Puzzle
29 SQL Puzzle | Multiple Comma Seperated Values Puzzle
28 SQL Puzzle | Remove Duplicate Values Puzzle
27 SQL Puzzle | 2 Decimal Puzzle
26 SQL Puzzle | Fill Missing Values Puzzle
25 SQL Puzzle | Company Code Puzzle
24 SQL Puzzle | The Double Join Puzzle
23 SQL Puzzle | Ignore Duplicate Values Puzzle 
22 SQL Puzzle | Group By XML Path Puzzle
21 SQL | Fishbone Salary puzzle
20 SQL | The Male and Female Puzzle
19 SQL Puzzle | Normalize(Divide) Amount and Months Puzzle 
18 SQL Puzzle | Covert Comma Separated Values to a Table using Cross Apply & XML Puzzle
17 SQL Puzzle | The Candidate Joining Puzzle
16 SQL Puzzle | Consecutive Wins for India Puzzle
15 SQL Puzzle | The Work Order Puzzle
14 SQL | The football Puzzle
13 SQL Puzzle | Gold Rate Puzzle
12 SQL | Group By on Multiple columns Puzzle
11 SQL | Remove ALL Zero Puzzle
10 SQL Puzzle | Department Wise 2nd Highest Salary Puzzle
9 SQL Puzzle | Developer Salary & the Manager Puzzle
8 SQL Puzzle | Finding Maximum Value from multiple columns
7 SQL Puzzle | Sum of Previous Value Puzzle
6 SQL Puzzle | Nth Highest Salary
5 SQL | Remove Unwanted Null Values Puzzle
4 SQL Puzzle | Movie & Role Puzzle
3 SQL Puzzle | BirthDay Puzzle
2 SQL | Finding Next Value Puzzle
1 SQL | Finding Previous Value Puzzle
Advertisements

Leave a comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s