我很难在SQLite的Windows框架规范中添加数字。我在SQLITE中使用R。尽管如果您知道如何在SQL中执行此操作,那也很有帮助。
这里是sqlite窗口函数文档的链接-尽管很难理解应在哪里放置数值。
https://www.sqlite.org/windowfunctions.html
特别是我正在查看帧边界部分。
我希望收到错误消息:
Error: unsupported frame specification
有什么想法吗?
我的代码如下:
"create temp table forward_looking as
SELECT *,
COUNT( CASE channel WHEN 'called_office' THEN 1 ELSE null END)
OVER (PARTITION by special_digs
ORDER BY time
RANGE FOLLOWING 604800)
AS new_count
from my_data
")
基本上,代码应查看以unix纪元时间表示的时间列,然后提前7天(unix时为604800),然后向new_count添加一个计数。并逐行执行此操作。
我想我可能在RANGE FOLLOWING
部分中使用了错误的数字?
我认为您想要:
create temp table forward_looking as
select
d.*,
count(*) filter(where channel = 'called_office') over (
partition by special_digs
order by time
range between current row and 604800 following
) as new_count
from my_data d