我正在做卡内基梅隆大学https://15445.courses.cs.cmu.edu/fall2018/homework1/上一次数据库系统课程的家庭作业。 我被困在问题4上。作业解决方案中给出的有关SQLite3的正确SQL查询如下,但我对GROUP BY子句之前的ROTFTIME和datetime函数感到困惑,并且从ROUND(SUM ...
开始WITH dates AS (SELECT date(start_time) AS tdate
FROM trip
UNION
SELECT date(end_time) AS tdate
FROM trip)
SELECT tdate,
ROUND(SUM(strftime('%s', MIN(datetime(end_time), datetime(tdate, '+1
day'))) - strftime('%s', MAX(datetime(start_time), datetime(tdate))))
* 1.0 / (SELECT count(distinct(bike_id))
FROM trip
WHERE bike_id <= 100), 4) AS avg_duration
FROM trip, dates
WHERE bike_id <= 100
AND datetime(start_time) < datetime(tdate, '+1 day')
AND datetime(end_time) > datetime(tdate)
GROUP BY tdate
ORDER BY avg_duration DESC LIMIT 10;