I checked the following questions:
Fetch the row which has the Max value for a column
Columns : account_number, app_guid, time_event_published(epoch time).
I want the latest row of each app_guid
for a given account_number
PLUS oldest time_event_published
of the same account_number
for each app_guid
in another column of the latest row.
SELECT id, account_number, app_guid, time_event_published , <oldest_time_event_published_for_2152331553409959696> FROM (
SELECT id, account_number, app_guid, time_event_published,
RANK() OVER (PARTITION BY app_guid ORDER BY time_event_published DESC) dest_rank
FROM event where account_number=2152331553409959696
) where dest_rank = 1;
I am only able to think of another DB hit with same query with ASC
. Is there any other way and how to approach this requirement?
DB Entries:
2152331553409959696, TEST-ONE-APP_GUID, 25-JAN
2152331553409959696, TEST-ONE-APP_GUID, 1-JAN
2152331553409959696, TEST-TWO-APP_GUID, 25-FEB
2152331553409959696, TEST-TWO-APP_GUID, 1-FEB
Required Result:
2152331553409959696, TEST-ONE-APP_GUID, 25-JAN, 1-JAN
2152331553409959696, TEST-TWO-APP_GUID, 25-FEB, 1-FEB