Variation by day of week
Does the time required to complete a request vary by the day of the week on which the request was created?
We can get the name of the day of the week by converting a timestamp to character data:
to_char(date_created, 'day')
But character names for the days of the week sort in alphabetical, not chronological, order. To get the chronological order of days of the week with an integer value for each day, we can use:
EXTRACT(DOW FROM date_created)
DOW stands for "day of week."
Deze oefening maakt deel uit van de cursus
Exploratory Data Analysis in SQL
Oefeninstructies
- Select the name of the day of the week the request was created (
date_created) asday. - Select the mean time between the request completion (
date_completed) and request creation asduration. - Group by
day(the name of the day of the week) and the integer value for the day of the week (use a function). - Order by the integer value of the day of the week using the same function used in
GROUP BY.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
-- Select name of the day of the week the request was created
SELECT ___(___, ___) AS day,
-- Select avg time between request creation and completion
___(___ - ___) AS duration
FROM evanston311
-- Group by the name of the day of the week and
-- integer value of day of week the request was created
GROUP BY day, EXTRACT(___ ___ ___)
-- Order by integer value of the day of the week
-- the request was created
ORDER BY EXTRACT(___ ___ ___);