Tags

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,


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

http://MSBISkills.com

Advertisements