So i have a table called Value. This table has columns called: VALUE_ID, VALUE, HR, VALUE_TYPE. I am trying to grab not only the maximum value but also the HR (and ultimately the day) that the Maximum Value Occurred.
Below is some sample data:
VALUE_ID VALUE HR VALUE_TYPE
1 75 DEC-25-2018 01:00:00 AM Bananas
2 10 DEC-25-2018 01:00:00 AM Bananas
3 787 DEC-25-2018 05:00:00 PM Bananas
I want:
(For Hourly)
MAX(Value) HR Value_Type
75 DEC-25-2018 01:00:00 AM Bananas
787 DEC-25-2018 05:00:00 PM Bananas
(For Day)
MAX(Value) HR(Day) Value_Type
787 DEC-25-2018 05:00:00 PM Bananas
I've tried the following (this is probably completely wrong but im not sure how to combine columns from two separate queries into one table):
select max(value) as max_value
, Value_Type
from value
group by value_type
UNION
select HR from
from value
where value = (select max(value) as max_value
, Value_Type
from value
group by value_type;
Thanks in advance.