Last active
July 14, 2019 06:58
-
-
Save jeff/4533909 to your computer and use it in GitHub Desktop.
Looking at grouping circ counts by "week" with some consideration given to avoiding partial weeks at the start of the data summarized.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This will show counts grouped by weeks, but will | |
-- likely include a partial week at the start | |
-- (check the "days_in_sample" column) | |
SELECT date_trunc('week',xact_start)::date week, | |
circ_lib, | |
count(distinct xact_start::date) days_in_sample, | |
count(*) circ_count | |
FROM action.circulation | |
WHERE xact_start > '2012-12-01' | |
GROUP BY 1,2 | |
ORDER BY 1,2; | |
-- This will ensure that we have a | |
-- full week at the start of the data | |
-- (assuming that is possible) | |
-- again, see the "days_in_sample" column | |
SELECT date_trunc('week',xact_start)::date week, | |
circ_lib, | |
count(distinct xact_start::date) days_in_sample, | |
count(*) circ_count | |
FROM action.circulation | |
WHERE xact_start > '2012-12-01' | |
GROUP BY 1,2 | |
HAVING date_trunc('week',xact_start)::date > '2012-12-01' | |
ORDER BY 1,2; | |
-- The example just before this excludes partial | |
-- weeks, at the expense of excluding data within | |
-- the range we requested. | |
-- This example favors pulling earlier than the | |
-- specified date in order to ensure a full week | |
SELECT date_trunc('week',xact_start)::date week, | |
circ_lib, | |
count(distinct xact_start::date) days_in_sample, | |
count(*) circ_count | |
FROM action.circulation | |
WHERE xact_start::date >= date_trunc('week', '2012-12-01'::date)::date | |
GROUP BY 1,2 | |
ORDER BY 1,2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment