Advertisement
Guest User

Untitled

a guest
May 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. CREATE TABLE component_data
  2. ("id" int, "generated_date" timestamp, "removed_date" timestamp, "active" bool, "owner_rel_id" int)
  3. ;
  4.  
  5. CREATE TABLE dates
  6. ("fulldate" date, "year" int, "month" int, "day" int)
  7. ;
  8.  
  9. INSERT INTO component_data
  10. ("id", "generated_date", "removed_date", "active", "owner_rel_id")
  11. VALUES
  12. (2507562, '2016-04-23 07:37:51', NULL, 't', 977720),
  13. (2507563, '2016-04-23 07:37:51', NULL, 't', 977720),
  14. (2507564, '2016-04-23 07:37:51', NULL, 't', 977720),
  15. (2507565, '2016-04-23 07:37:51', NULL, 't', 977720),
  16. (2507566, '2016-04-23 07:37:51', NULL, 't', 977720),
  17. (2507567, '2016-04-23 07:37:51', NULL, 't', 977720),
  18. (1586966, '2013-09-16 18:28:23', NULL, 't', 653531),
  19. (1586854, '2013-09-16 17:02:43', NULL, 't', 678806),
  20. (2363032, '2015-12-26 13:59:02', NULL, 't', 666874),
  21. (1586929, '2013-09-16 18:04:41', NULL, 't', 678820),
  22. (1587071, '2013-09-16 18:47:32', NULL, 't', 463631),
  23. (1587072, '2013-09-16 18:53:10', NULL, 't', 678834),
  24. (2363033, '2015-12-26 13:59:02', NULL, 't', 666874),
  25. (2235362, '2015-09-07 17:30:58', NULL, 't', 882233),
  26. (1587065, '2013-11-17 05:12:42', '2016-05-16 09:12:58-04', NULL, 678831),
  27. (1587785, '2013-09-19 00:00:00', NULL, 't', 679404),
  28. (2363036, '2015-12-26 14:15:59', NULL, 't', 713679),
  29. (1581675, '2013-09-25 00:00:00', '2016-05-16 09:34:26-04', NULL, 677199),
  30. (1210333, '2013-02-14 00:00:00', NULL, 't', 681094),
  31. (1592753, '2013-09-24 18:04:49', NULL, 't', 680679),
  32. (1593061, '2013-09-27 00:00:00', '2016-05-15 14:28:35-04', NULL, 680794),
  33. (1593064, '2013-09-27 00:00:00', '2016-05-15 14:28:35-04', NULL, 680794)
  34. ;
  35.  
  36. INSERT INTO dates
  37. ("fulldate", "year", "month", "day")
  38. VALUES
  39. ('2016-05-01 00:00:00', 2016, 5, 1),
  40. ('2016-05-02 00:00:00', 2016, 5, 2),
  41. ('2016-05-03 00:00:00', 2016, 5, 3),
  42. ('2016-05-04 00:00:00', 2016, 5, 4),
  43. ('2016-05-05 00:00:00', 2016, 5, 5),
  44. ('2016-05-06 00:00:00', 2016, 5, 6),
  45. ('2016-05-07 00:00:00', 2016, 5, 7),
  46. ('2016-05-08 00:00:00', 2016, 5, 8),
  47. ('2016-05-09 00:00:00', 2016, 5, 9),
  48. ('2016-05-10 00:00:00', 2016, 5, 10),
  49. ('2016-05-11 00:00:00', 2016, 5, 11),
  50. ('2016-05-12 00:00:00', 2016, 5, 12),
  51. ('2016-05-13 00:00:00', 2016, 5, 13),
  52. ('2016-05-14 00:00:00', 2016, 5, 14),
  53. ('2016-05-15 00:00:00', 2016, 5, 15),
  54. ('2016-05-16 00:00:00', 2016, 5, 16),
  55. ('2016-05-17 00:00:00', 2016, 5, 17),
  56. ('2016-05-18 00:00:00', 2016, 5, 18),
  57. ('2016-05-19 00:00:00', 2016, 5, 19),
  58. ('2016-05-20 00:00:00', 2016, 5, 20),
  59. ('2016-05-21 00:00:00', 2016, 5, 21),
  60. ('2016-05-22 00:00:00', 2016, 5, 22),
  61. ('2016-05-23 00:00:00', 2016, 5, 23),
  62. ('2016-05-24 00:00:00', 2016, 5, 24),
  63. ('2016-05-25 00:00:00', 2016, 5, 25)
  64. ;
  65.  
  66. SELECT
  67. d.fulldate,
  68. cd.id,
  69. cd.owner_rel_id,
  70. cd.generated_date,
  71. cd.removed_date,
  72. cd.active
  73. FROM
  74. component_data cd
  75. INNER JOIN dates d ON (cd.generated_date <= d.fulldate) AND ((cd.removed_date >= d.fulldate) OR cd.active)
  76. WHERE
  77. d.fulldate IN ('2016-05-16', '2016-05-17')
  78. ORDER BY
  79. cd.id,
  80. d.fulldate;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement