Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. customer
  2. +---------------------------------------------------------------------------------------------+
  3. | id | email | firstname | lastname | no_pub | customer_address |
  4. |---------------------------------------------------------------------------------------------|
  5. | 1 | martin@domain.com | Martin | Scorcese | 0 | 4 |
  6. | 2 | robert@domain.com | Robert | De Niro | 0 | 7 |
  7. | 3 | bruce@domain;com | Bruce | Willis | 0 | 10 |
  8. +---------------------------------------------------------------------------------------------+
  9.  
  10. address
  11. +------------------------------------------+
  12. | id | city | zipcode |
  13. |------------------------------------------|
  14. | 4 | Paris | 75001 |
  15. | 7 | Marseille | 13000 |
  16. | 10 | Bordeaux | 33000 |
  17. +------------------------------------------+
  18.  
  19. sf_geo_cities
  20. +------------------------------------------+
  21. | id | region_id | zipcode |
  22. |------------------------------------------|
  23. | 1 | 1 | 75001 |
  24. | 2 | 2 | 13000 |
  25. | 2 | 3 | 33000 |
  26. +------------------------------------------+
  27.  
  28. sf_geo_regions
  29. +------------------------------------------+
  30. | id | name | zipcode |
  31. |------------------------------------------|
  32. | 1 | Ile-de-France | 75001 |
  33. | 2 | Cote d'Azur | 13000 |
  34. | 2 | Gironde | 33000 |
  35. +------------------------------------------+
  36.  
  37. +---------------------------------------------------------------------------------------------+
  38. | id | email | firstname | lastname | city | region |
  39. |---------------------------------------------------------------------------------------------|
  40. | 1 | martin@domain.com | Martin | Scorcese | Paris | Ile-de-France |
  41. | 2 | robert@domain.com | Robert | De Niro | Marseille | Cote d'Azur |
  42. | 3 | bruce@domain;com | Bruce | Willis | NULL | NULL |
  43. +---------------------------------------------------------------------------------------------+
  44.  
  45. SELECT c.id, c.email, c.firstname, c.lastname, gc.name, gr.name
  46. FROM customer c
  47. LEFT JOIN address ad ON ad.id = c.customer_address
  48. JOIN sf_geo_cities gc ON gc.zipcode = ad.zipcode
  49. JOIN sf_geo_regions gr ON gr.id = gc.region_id
  50. WHERE no_pub = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement