Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. email_address | brand | region | area | site | lowest_distinct_level
  2. ----------------|-------|--------|------|------|----------------------
  3. alpha@gmail.com | 1 | 1 | 1 | 2 |
  4. beta@gmail.com | 1 | 1 | 2 | 0 |
  5. gamma@gmail.com | 1 | 1 | 2 | 2 |
  6. zeta@gmail.com | 1 | 2 | 0 | 0 |
  7.  
  8. select email_address, brand, region, area, site,
  9. case when site = 1 then 'site'
  10. else case when area = 1 then 'area'
  11. else case when region = 1 then 'region'
  12. else case when brand = 1 then 'brand'
  13. else ''
  14. end
  15. end
  16. end
  17. end
  18. from mm;
  19.  
  20. +-----------------+-------+--------+------+------+--------+
  21. | email_address | brand | region | area | site | case |
  22. +-----------------+-------+--------+------+------+--------+
  23. | alpha@gmail.com | 1 | 1 | 1 | 2 | area |
  24. +-----------------+-------+--------+------+------+--------+
  25. | beta@gmail.com | 1 | 1 | 2 | 0 | region |
  26. +-----------------+-------+--------+------+------+--------+
  27. | gamma@gmail.com | 1 | 1 | 2 | 2 | region |
  28. +-----------------+-------+--------+------+------+--------+
  29. | zeta@gmail.com | 1 | 2 | 0 | 0 | brand |
  30. +-----------------+-------+--------+------+------+--------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement