我试图解决的任务是: 在一个长方形1450米的正方形牢房内,大英博物馆的自行车站,Bloomsbury在4个小时的时间从早上6点开始。
我有两张桌子, 站表和使用表。但是,在运行我的查询后,所有行都是空的!
SELECT ce.stationID,
il.name,
il.easting,
il.northing,
il.capacity,
ce.t,
ROUND(AVG(availableBikes) ,1) as Average,
ROUND(AVG(availableBikes)/capacity*100,1) AS Percentage
FROM tflBikeUsagehour ce,
tflStations il
where il.usageId=ce.stationID
and datetime (t,'06:00:00')>6
AND datetime (t,' 10:00:00')<10
AND il.easting BETWEEN (SELECT easting-(1450*0.5) FROM tflstations
WHERE name='British Museum, Bloomsbury')
AND (SELECT easting+(1450*0.5) FROM tflstations
WHERE name='British Museum, Bloomsbury')
AND il.northing BETWEEN (SELECT northing-(1450*0.5) FROM tflstations
WHERE name='British Museum, Bloomsbury')
AND (SELECT northing+(1450*0.5) FROM tflstations
WHERE name='British Museum, Bloomsbury')
and ce.t between (select datetime(t,'06:00:00')<6 as tf from tflbikeusagehour)
and (select datetime(t,'10:00:00')>10 from tflbikeusagehour)
GROUP BY ce.t
ORDER BY ce.t;
我的问题是日期时间格式!我使用它错了吗?
答案 0 :(得分:0)
datetime function不能以这种方式使用。
要检查时间戳是否在某个范围内,请使用如下表达式:
time(t) BETWEEN '06:00:00' AND '09:59:59'
如果列t
已使用格式hh:mm:ss
,则可以将time(t)
替换为t
。