Tags
Complex SQL Challenges, Complex TSQL Challenge, Interview Qs.SQL SERVER Questions, Interview Questions on SQL, InterviewQuestions, InterviewQuestions for SQL, Learn complex SQL, Learn SQL, Learn T-SQL, MSBISkills, PL/SQL Challenges, Puzzles, Queries for SQL Interview, SQL, SQL 2012, SQL 2014, SQL 2014 Interview Questions, SQL Challenge, SQL Challenges, SQL FAQs, SQL Interview, SQL Interview Puzzles, SQL IQs, SQL pl/sql puzzles, SQL Puzzles, SQL Queries, SQL Server 2012 Analysis Services, SQL Server Data Tools, SQL SERVER Interview questions, SQL SERver performance, SQL SERVER Puzzles, SQL SERVER2005/2008, SQL Skills, SQL Sudoku, SQLPuzzles, SQLQueries, SQLSERVER, T SQL Puzzles, T-SQL Challenge, Tough SQL Challenges, Tough SQL Puzzles, TSQL, TSQL Challenge, TSQL Challenges, TSQL Interview questions, TSQL Queries
T-SQL Query | [ The Max Puzzle ]
The puzzle is simple. Here we have find maximum from both the columns from sample input table. Please check out the sample input and expected output for details.
Sample Input
Exchange_Rate | Date |
0.011978 | 14-07-2013 |
0.01198 | 13-07-2013 |
0.011979 | 14-07-2013 |
0.011979 | 13-07-2013 |
0.01199 | 10-07-2013 |
0.011999 | 09-07-2013 |
Expected output
Date | Exchange_Rate |
14-07-2013 | 0.011999 |
Rules/Restrictions
- The solution should be should use “SELECT” statement or “CTE”.
- Add your solution(s) in the comments section or send you solution(s) to pawankkmr@gmail.com
Script
Use the below script to generate the source table and fill them up with the sample data.
-- --Create Data CREATE TABLE MAxExchange ( Exchange_Rate FLOAT , Date DATE ) --Insert Data INSERT INTO MAxExchange(Exchange_Rate,Date) VALUES (0.011978,'2013-07-14' ), (0.011980, '2013-07-13'), (0.011979, '2013-07-14'), (0.011979, '2013-07-13'), (0.011990, '2013-07-10'), (0.011999, '2013-07-09') -- |
UPDATE – 11-Apr-2015 – Solution 1
-- --Solution 1 SELECT MAX(Exchange_Rate) Exchange_Rate , MAX(Date) Date FROM MAxExchange -- |
Add a comment if you have any other solution in mind. We all need to learn.
Keep Learning