TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sai Reddy
NA
214
32.3k
Find starting value and ending value
Aug 1 2018 7:52 AM
Hi, My friend faced an interview question.
Input:
CurrencyValue
Value
100
1
200
1
300
1
99
1
123
2
321
2
115
2
34
3
37
3
89
3
Output:
Value
Started
Ended
1
100
99
2
123
115
3
34
89
I tried the following query.
WITH cte
AS (SELECT currencyvalue,
value,
Row_number()
OVER(
partition BY value
ORDER BY value DESC ) rk
FROM table_max_min)
SELECT value,
Min(rk)minimum,
Max(rk)maximum
FROM cte
GROUP BY value
Reply
Answers (
3
)
query optimization
The Changed value in this cell was not recognized as valid.