Advertisement
Guest User

Untitled

a guest
Jan 4th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. user_id email gender age name
  2. 1 a@a.com m 30 rob
  3. 2 a@a.com m 31 robert
  4. 3 b@b.com f 18 lucie
  5. 4 b@b.com f 22 lulu
  6. 5 c@c.com m 10 kim
  7. 6 c@c.com f 18 kim
  8. 7 c@c.com f 08 kim
  9. 8 d@d.com f 18 JJ
  10. 9 d@d.com m 22 Jay
  11. 10 e@e.com f 88 Bill
  12. 11 e@e.com f 88 Will
  13. 12 e@e.com f 60 Will
  14. 13 f@f.com m 70 George
  15.  
  16. subscription_id user_id subsciption_type active_indicator
  17. 1 2 Magazine Yes
  18. 2 3 Music CD No
  19. 3 3 Magazine Yes
  20. 4 3 Video Yes
  21. 5 8 Magazine Yes
  22. 6 9 Video Yes
  23. 7 10 Magazine No
  24. 8 13 Magazine yes
  25.  
  26. subscription_id action timestamp
  27. 1 Renewal 2002-sep-10
  28. 2 Renewal 2002-Jan-01
  29. 2 Cancellation 2002-Feb-01 ,
  30. 3 Renewal 2002-Aug-20
  31. 4 Renewal 2002-Aug-01
  32. 4 Renewal 2002-Sep-01
  33. 5 Renewal 2002-Aug-01
  34. 6 Renewal 2001-Sep-01
  35. 7 Renewal 2002-Sep-01
  36. 7 Cancellation 2002-Sep-10
  37.  
  38. a@a.com m 31 robert
  39. b@b.com f 22 lulu
  40. c@c.com f 08 kim
  41. d@d.com m 22 Jay
  42. e@e.com f 60 Will
  43.  
  44. select u.user_id, email, gender, age, name
  45. from users u left join subscriptions s
  46. on u.user_id = s.user_id
  47. where s.user_id is null
  48. or s.active_indicator='No'
  49. or u.user_id in (
  50. select u.user_id
  51. from subscriptions s,transactions t, users u
  52. where u.user_id = s.user_id
  53. and s.subscription_id = t.subscription_id
  54. and t.`action`='Renewal'
  55. and s.active_indicator='Yes'
  56. and month(timestamp) = 9
  57. )
  58.  
  59. 1 a@a.com m 30 rob
  60. 4 b@b.com f 22 lulu
  61. 5 c@c.com m 10 kim
  62. 6 c@c.com f 18 kim
  63. 7 c@c.com f 8 kim
  64. 11 e@e.com f 88 will
  65. 12 e@e.com f 60 will
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement