我必须从下表中获得在给定的一天中至少观看一个视频的用户数和第二天返回以观看至少一个视频的用户数。我已经能够通过使用count语句获得计数,但是由于某些原因,它只显示第一个日期?到目前为止,我掌握的代码是:
SELECT date, COUNT(user_id) from clickstream_videos WHERE event_name = 'video_play'
更新---
我可以让下面的查询在microsoftsqlserver中工作,有什么建议可以让它在myphp上工作吗?
WITH uservideoviewvideo (date, (user_id) AS
(SELECT DISTINCT date, user_id
FROM clickstream_videos
WHERE event_name ='video_play' and user_id IS NOT NULL)
SELECT currentday.date AS date, COUNT(currentday.user_id) AS users_view_videos, COUNT(nextday.user_id) AS users_view_next_day
FROM userviewvideo currentday
LEFT JOIN userviewvideo nextday ON currentday.user_id = nextday.user_id AND DATEADD(DAY, 1, currentday.date) = nextday.date
GROUP BY currentday.date
1条答案
按热度按时间unguejic1#
你好像想要
lag()
以及group by
:注意,日期函数高度依赖于数据库。因此,在数据库中比较日期的确切语法可能不同。