如何给出其中'选择列时选择查询的条件?
我想在执行Select语句时在列选择中提供条件。
我想进行总计_timeonsite的平均值,重命名,并希望平均为Jun'20,Jul'20和Aug'20对访客的月份的平均值。
而且,整个查询的范围必须仅是8月20日的月份。因此,我想对total_timeonsite限制,以便将Jun'20,Jul'20和8月20日的几个月的值与访客相提并论。
select FULLVISITORID AS VISITOR_ID,
VISITID AS VISIT_ID,
VISITSTARTTIME_TS,
USER_ACCOUNT_TYPE,
(select AVG(TOTAL_TIMEONSITE) AS AVG_TOTAL_TIME_ON_SITE_LAST_3M FROM "ACRO_DEV"."GA"."GA_MAIN" WHERE
(cast((visitstarttime_ts) as DATE) >= to_date('2020-06-01 00:00:00.000') and CAST((visitstarttime_ts) AS DATE) <= to_date('2020-08-31 23:59:00.000'))
GROUP BY TOTAL_TIMEONSITE),
CHANNELGROUPING,
GEONETWORK_CONTINENT
from "ACRO_DEV"."GA"."GA_MAIN"
where (FULLVISITORID) in (select distinct (FULLVISITORID) from "ACRO_DEV"."GA"."GA_MAIN" where user_account_type in ('anonymous', 'registered')
and (cast((visitstarttime_ts) as DATE) >= to_date('2020-08-01 00:00:00.000') and CAST((visitstarttime_ts) AS DATE) <= to_date('2020-08-31 23:59:00.000')));
问题在于,它为我提供了“ total_timeonsite的选择子查询”为结果列名称,该列中的值都是相同的,但我希望这些值对访问者来说是唯一的。
I want to give condition in a column selection while performing the select statement.
I want to perform average of TOTAL_TIMEONSITE, RENAME IT, and want to average it for the values existing in the month of Jun'20, Jul'20 and Aug'20 against a visitor.
Also the range of the whole query must be the month of Aug'20 only. So I want to put the constraint on TOTAL_TIMEONSITE so that it averages the values for the months of Jun'20, Jul'20 and Aug'20 against a visitor.
select FULLVISITORID AS VISITOR_ID,
VISITID AS VISIT_ID,
VISITSTARTTIME_TS,
USER_ACCOUNT_TYPE,
(select AVG(TOTAL_TIMEONSITE) AS AVG_TOTAL_TIME_ON_SITE_LAST_3M FROM "ACRO_DEV"."GA"."GA_MAIN" WHERE
(cast((visitstarttime_ts) as DATE) >= to_date('2020-06-01 00:00:00.000') and CAST((visitstarttime_ts) AS DATE) <= to_date('2020-08-31 23:59:00.000'))
GROUP BY TOTAL_TIMEONSITE),
CHANNELGROUPING,
GEONETWORK_CONTINENT
from "ACRO_DEV"."GA"."GA_MAIN"
where (FULLVISITORID) in (select distinct (FULLVISITORID) from "ACRO_DEV"."GA"."GA_MAIN" where user_account_type in ('anonymous', 'registered')
and (cast((visitstarttime_ts) as DATE) >= to_date('2020-08-01 00:00:00.000') and CAST((visitstarttime_ts) AS DATE) <= to_date('2020-08-31 23:59:00.000')));
The issue is that it is giving me the 'select subquery for TOTAL_TIMEONSITE' as the resultant column name and the values in that column are all same but I want the values to be unique for visitors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,对于雪花:
所以我要假设
访问starttime_ts
是timestamp
因此cast((((访问starttime_ts)作为日期)
与`extstarttime_ts :: date'giss:
-ADS :: DATE'给予:因此,日期范围也可以更简单
无论如何,如果我知道您想要什么像使用CTE一样将其写入(对我来说)更可读性:
但是,如果您希望它是子选择,它们是相同的:
So for Snowflake:
So I am going to assume
visitstarttime_ts
is atimestamp
thuscast((visitstarttime_ts) as DATE)
is the same as `visitstarttime_ts::date'gives:
and thus the date range also can be simpler
Anyways, if I understand what you want I would write it like using CTE to make it more readable (to me):
But if you want that to be sub-selects, they are the same: