Seconds or no seconds?
In the video, you saw how DATEDIFF() can be used to calculate the trip time by finding the difference between Start and End time, but how do you know the dataset includes seconds in the transactions?
Here, you'll use DATEPART() to see how many transactions have seconds greater than zero and how many have them equal to zero. Then you can evaluate if this is an appropriate amount. The CASE statement will segregate the dataset into two categories.
Diese Übung ist Teil des Kurses
<Kurs>Writing Functions and Stored Procedures in SQL Server</Kurs>Übungsanweisungen
- Complete the first
CASEstatement, usingDATEPART()to evaluate theSECONDdate part ofStartDate. - Complete the second
CASEstatement in theGROUP BYthe same way.
Interaktive praktische Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
SELECT
-- Count the number of IDs
COUNT(ID) AS Count,
-- Use DATEPART() to evaluate the SECOND part of StartDate
"StartDate" = CASE WHEN ___(___, ___) = 0 THEN 'SECONDS = 0'
WHEN ___(___, ___) > 0 THEN 'SECONDS > 0' END
FROM CapitalBikeShare
GROUP BY
-- Use DATEPART() to Group By the CASE statement
CASE WHEN ___(___, ___) = 0 THEN 'SECONDS = 0'
WHEN ___(___, ___) > 0 THEN 'SECONDS > 0' END