查找在注册后的特定时间内登录的用户

时间:2018-11-21 09:15:31

标签: sql impala

我试图弄清楚如何处理以下问题:

我有表<mvc:View controllerName="xy.controller.Master" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" > <App> <pages> <Page title="{i18n>title}"> <content> <Image src="img/Blume.PNG" densityAware="false" width="" useMap="Map"> <layoutData> <FlexItemData growFactor="1"/> </layoutData> </Image> <html:map name="Map" id="Map"> <html:area alt="" title="" href="www.google.de" shape="poly" coords="384,505,444,507,444,528,390,527"/> <html:area alt="" title="" href="www.google.de" shape="poly" coords="426,582,494,583,494,636,426,632"/> </html:map> </content> </Page> </pages> </App> </mvc:View>

registrations

和带有+---------+---------------------+ | user_id | reg_date | +---------+---------------------+ | a | 2018-11-01 20:47:46 | | b | 2018-11-02 21:07:15 | | c | 2018-11-03 05:24:31 | +---------+---------------------+ 的表:

logins

因此,我需要让用户在注册后的第二天(注册后24到48小时之间)至少登录一次,并在登录页面上显示+---------+---------------------+ | user_id | login_date | +---------+---------------------+ | a | 2018-11-01 21:30:46 | | a | 2018-11-01 21:35:15 | | a | 2018-11-01 22:22:22 | | ... | | +---------+---------------------+ user_id和最高登录信息第二天。

我最终得到了以下解决方案:

register_date

但是我不确定我的解决方案,尽管看起来不错。您能否检查一下并提出更简便的计算方法?

1 个答案:

答案 0 :(得分:0)

这应该有效

SELECT r.user_id, 
       r.reg_date, 
       Max(l.login_date), 
       Count(l.login_date) 
FROM   registrations r, 
       logins l 
WHERE  r.user_id = l.user_id 
       AND l.login_date BETWEEN ( r.reg_date + interval '1' day ) AND ( 
                                r.reg_date + interval '2' day )
group by l.login_date        
having Count(l.login_date)>=1 
;