这段看了好几遍也不知道是哪里错了,输入也都是英文格式的呀,报错如下:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'precending)/count(ym) over(partition by device_id order by ym rows 2 precending)' at line 3"
select device_id,
ym,
sum(cnt) over (partition by device_id order by ym) as sum_cnt,
round(sum(cnt) over (partition by device_id order by ym rows 2 precending)/count(ym) over(partition by device_id order by ym rows 2 precending),2 ) as avg3_cnt,
sum(cnt) over (order by ym)as total_cnt from
(
select device_id,substring(event_date,1,7 ) as ym,
count(question_id) as cnt
from question_practice_detail
group by device_id,ym
) a
order by device_id,ym