我需要从mdl_logstore_standard_log
中选择行,条件为timecreated
应该在过去五天上午7:30到下午4:30之间。我怎样才能在过去5天和时间内完成组合。这就是我所拥有的
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= DATE_SUB(CURDATE(), INTERVAL 5 DAY)
GROUP by userid
timecreated
位于unixtimestamp
答案 0 :(得分:1)
你也可以这样做
SELECT
*
FROM mdl_logstore_standard_log
WHERE timecreated >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 5 DAY)
AND (
(timecreated % 86400)
BETWEEN UNIX_TIMESTAMP('1970-01-01 07:30')
AND UNIX_TIMESTAMP('1970-01-01 16:30')
)
GROUP by userid
timecreated % 86400
会在几秒钟内返回残留物。
如果残留在1970-01-01 07:30
和1970-01-01 16:30
之间,那么您的条件实际上已经满足。
注意:强>
GROUP BY
。
(@scaisEdge已经说过了)timecreated
字段(如果有)答案 1 :(得分:0)
PLS试试这个
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= FROM_UNIXTIME(DATE_SUB(CURDATE(), INTERVAL 5 DAY))
GROUP by userid;
答案 2 :(得分:0)
你可以使用时间
SELECT * FROM mdl_logstore_standard_log
WHERE FROM_UNIXTIME(timecreated) >= DATE_SUB(CURDATE(), INTERVAL 5 DAY)
AND time(FROM_UNIXTIME(timecreated))
between time('2016-01-01 07:30:00.0000' ) and time('2016-01-01 16:30:00.0000' )
GROUP by userid
请注意,您正在使用group by而不使用聚合函数..这可能会导致不连贯的结果...