列在unixtimestamp中的日期分组

时间:2016-10-23 02:59:37

标签: sqlite

我有一个在unixtimestamp(ms)中有时间的表,我想将时间仅转换为白天和每天使用聚合函数COUNT转换。我尝试了这个,但它没有用:

SELECT
strftime('%d',(timestamp+1465876799998)/1000, 'unixepoch') a
COUNT(strftime('%d',(timestamp+1465876799998)/1000, 'unixepoch'))
FROM
clicks_train_
GROUP BY
strftime('%d',(timestamp+1465876799998)/1000, 'unixepoch')
ORDER BY strftime('%d',(timestamp+1465876799998)/1000, 'unixepoch') DESC
LIMIT 10;

1 个答案:

答案 0 :(得分:1)

只需使用当前格式说明符的strftime

SELECT strftime('%Y-%m-%d', timestamp / 1000, 'unixepoch'),
       COUNT(*)
FROM clicks_train_
GROUP BY strftime('%Y-%m-%d', timestamp / 1000, 'unixepoch')
ORDER BY strftime('%Y-%m-%d', timestamp / 1000, 'unixepoch') DESC
LIMIT 10;