SQL动态联接
需要为不同时间戳提供以下动态查询的建议吗 尝试添加以下条件(当天、1天、7天、15天、30天),dau_漏斗包含数百万条记录SQL动态联接,sql,amazon-redshift,Sql,Amazon Redshift,需要为不同时间戳提供以下动态查询的建议吗 尝试添加以下条件(当天、1天、7天、15天、30天),dau_漏斗包含数百万条记录 dc.at_date_ist between m.install_ist::date and m.install_ist::date + 0 dc.at_date_ist between m.install_ist::date and m.install_ist::date + 1 dc.at_date_ist between m.install_ist::date an
dc.at_date_ist between m.install_ist::date and m.install_ist::date + 0
dc.at_date_ist between m.install_ist::date and m.install_ist::date + 1
dc.at_date_ist between m.install_ist::date and m.install_ist::date + 7
dc.at_date_ist between m.install_ist::date and m.install_ist::date + 15
dc.at_date_ist between m.install_ist::date and m.install_ist::date + 30
查询连接子句:
select count(distinct user_id) from mapping m
left join dau_funnel dc on m.user_id = dc.custom__user_id and m.device_uuid = dc.device_uuid
and dc.at_date_ist between m.install_ist::date and m.install_ist::date + 7
使用条件聚合,并使用单独的计数表达式:
select
count(distinct user_id) as cnt_0,
count(distinct case when c.at_date_ist between m.install_ist::date and m.install_ist::date + 1 then user_id end) as cnt_1,
count(distinct case when dc.at_date_ist between m.install_ist::date and m.install_ist::date + 7 then user_id end) as cnt_7,
count(distinct case when dc.at_date_ist between m.install_ist::date and m.install_ist::date + 15 then user_id end) as cnt_15,
count(distinct case when dc.at_date_ist between m.install_ist::date and m.install_ist::date + 30 then user_id end) as cnt_30
from mapping m
left join dau_funnel dc
on m.user_id = dc.custom__user_id and m.device_uuid = dc.device_uuid;
此语法不受红移..任何其他Solution@SQL_Learner我一定错过了红移标签。请不要使用Postgres标记,除非您确实在使用该数据库。@SQL\U Learner。红移不支持此语法的哪一部分
COUNT DISTINCT
作为聚合函数()受支持,就像CASE
一样。这个SQL非常标准。@GordonLinoff最初,我在回答中使用了FILTER
。Redshift是Postgres的一个非常旧的版本,它显然还不支持过滤器。