insert into dim_result_lct_activy_config select Fact_id, LAST_VALUE(Fact_name), regexp_Replace( LAST_VALUE(Fact_start_time), '-|:|\s','') as startTime, regexp_Replace(LAST_VALUE(Fact_end_time),'-|:|\s','') as endTime, LAST_VALUE(Fstate) from db_act_config_t_act_logic_config groupby Fact_id
/** * Get dialect upsert statement, the database has its own upsert syntax, such as Mysql * using DUPLICATE KEY UPDATE, and PostgresSQL using ON CONFLICT... DO UPDATE SET.. * * @return None if dialect does not support upsert statement, the writer will degrade to * the use of select + update/insert, this performance is poor. */ defaultOptional<String> getUpsertStatement( String tableName, String[] fieldNames, String[] uniqueKeyFields) { return Optional.empty(); }
select to_char(SYSTIMESTAMP(),'yyyymmddhh24miss') fetl_time, * from ( select *, row_number() over(partitionby fid orderby fmodify_time desc,exp_time_stample_order desc) rn from db.table1 where fdate=20210101 ) t where rn=1
1 2 3 4 5 6 7 8 9 10 11
SELECTCOUNT(amount) OVER ( PARTITIONBYuser ORDERBY proctime ROWSBETWEEN2 PRECEDING ANDCURRENTROW) FROM Orders; SELECTCOUNT(amount) OVER w, SUM(amount) OVER w FROM Orders WINDOW w AS ( PARTITIONBYuser ORDERBY proctime ROWSBETWEEN2 PRECEDING ANDCURRENTROW) ;
insert into agg_result select user_id, page_id, 'ctr-type1'as result_type, sum( case when action_type ='click'then1else0 end ) OVER w / if( sum( case when action_type ='view'then1else0 end ) OVER w =0, 1, sum( case when action_type ='view'then1else0 end ) OVER w ) as result_value from user_action where 1=1 WINDOW w AS ( PARTITIONBY user_id, page_id, DATE_FORMAT(event_time,'yyyyMMdd') ORDERBY event_time RANGEBETWEENINTERVAL'1'DAY PRECEDING ANDCURRENTROW )
此外,OVER 窗口聚合还可以支持查询子句、关联查询、UNION ALL 等组合,并可以实现对关联出来的列进行聚合等复杂情况。