SHARE
TWEET

Untitled

a guest Jul 21st, 2017 438 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Priority   Attribute  sourceID
  2. 1          EMAIL      1
  3. 2          EMAIL      2
  4. 3          EMAIL      3
  5. 2          NAME       1
  6. 1          NAME       2
  7. 3          NAME       3
  8.    
  9. CustomerID  Name  Email              SourceID   Date
  10. 1           John  NULL               1          03/01/2017
  11. 1           NULL  John@email.com     3          01/01/2017
  12. 1           J     J.Smith@email.com  2          02/01/2017
  13.    
  14. CustomerID  Name  Email
  15. 1           John  J.Smith@email.com
  16.    
  17. select distinct
  18. FIRST_VALUE(c.Name IGNORE NULLS)
  19. OVER(PARTITION BY p.customerID
  20. ORDER BY r.PRIORITY, c.DATE  
  21. ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS EMAIL,
  22. FIRST_VALUE(c.Email IGNORE NULLS)
  23. OVER(PARTITION BY c.customerID
  24. ORDER BY r.PRIORITY, c.DATE
  25. ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS EMAIL,
  26. from Customer c
  27. join reference r on c.sourceID = r.sourceID
  28. ;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top