https://community.snowflake.com/s/article/COUNT-DISTINCT-and-NULLs
To count multiple distinct columns where null is not a value in any of the columns:
SELECT COUNT (DISTINCT COL1, COL2) FROM T1;
Otherwise
SELECT COUNT(*) FROM (SELECT DISTINCT COL1, COL2 FROM T1);
Parsing fields out of simple JSON like {key1:val1, key2:val2}
select json_extract_path_text(colume, 'json key') as extracted from table where primarykey ='data key';
Get difference in time in seconds when column is a data time string
select timediff(seconds, starttime, endtime) as diff from table where primarykey ='data key';
The default limit for Snowflake query results is 10,000 rows.
See column list and type
show columns in schema.table;
Show tables
show tables like '%name';
create temporary table
create temporary table name as select a, b, c from first_tabe where a>50
left join table 1 and 2 first match on table 2
select t1.a, t1.b, t1.c, t2.b from table 1 as t1 left join ( select field1, field2 row_number() over (particion by field1 order by length(field2) desc) as rn from table 2 where some condition ) t2 on t2.a = t1.a and t2.rn=1 order by t1.a;
How to Get First Row Per Group in Snowflake using row_number Function
How to Write a Common Table Expression in Snowflake
with free_users as ( select * from users where plan = 'free' ) select user_sessions.* from user_sessions inner join free_users on free_users.id = user_sessions.user_id order by free_users.id;