Guest User

Untitled

a guest
May 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Winning query?
  2.  
  3.  
  4. select *
  5. from leaguearchive
  6. where (orgid, userid, archivedate) in
  7. (select orgid, userid, max(archivedate)
  8. from leaguearchive
  9. group by orgid, userid, trunc(archivedate, 'dd') )
  10.  
  11.  
  12.  
  13. Hello there,
  14.  
  15. I have an archive tabled that is populated with new data every 15 minutes from our servers, it looks something like this.
  16.  
  17. Orgid NUMBER
  18. UserId NUMBER
  19. ArchiveDate Datetime
  20. Resources NUMBER
  21.  
  22.  
  23. MY QUESTION IS
  24.  
  25. I want to get the latest archived row each (OrgId,UserId) for each day. I've been using the below query to get the corrent org/user/archivedate, but I would like to get the corresponding Resources value to go with the row.
  26.  
  27. Is there a good way of doing this?
  28.  
  29.  
  30. select orgid, userid MAX(archivedate) as archivedate from leaguearchive
  31. group by trunc(archivedate, 'dd'), orgid, userid
Add Comment
Please, Sign In to add comment