-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwarmupQueries.sql
67 lines (57 loc) · 1.68 KB
/
warmupQueries.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ===========================================================================
// PART 1 - GETTING COMFORTABLE IN SNOWFLAKE
//
// get to know some basic parts of Snowflake and play with some demo data.
// ===========================================================================
// set context
USE ROLE OKC_MEETUP_ROLE;
USE WAREHOUSE OKC_MEETUP_WH;
// run a big, bulky query
SELECT
l_returnflag,
l_linestatus,
SUM(l_quantity) AS sum_qty,
SUM(l_extendedprice) AS sum_base_price,
SUM(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
AVG(l_quantity) AS avg_qty,
AVG(l_extendedprice) AS avg_price,
AVG(l_discount) AS avg_disc,
COUNT(*) AS count_order
FROM
SNOWFLAKE_SAMPLE_DATA.TPCH_SF100.LINEITEM
WHERE
l_receiptdate <= DATEADD(DAY, -90, TO_DATE('1998-12-01'))
GROUP BY
l_returnflag,
l_linestatus
ORDER BY
l_returnflag,
l_linestatus;
// Let's shift to some weather data.
// How many weather records are there?
SELECT COUNT(*) / 1000 / 1000 FROM SNOWFLAKE_SAMPLE_DATA.WEATHER.WEATHER_14_TOTAL;
// View the semi-strucutred data directly in the table
SELECT
*
FROM
SNOWFLAKE_SAMPLE_DATA.WEATHER.WEATHER_14_TOTAL
LIMIT 10;
// Select json elements directly from the json document in column V
SELECT
V:"time",
V:"city"."name",
V:"city"."country",
V:"main"."temp",
V:"weather"
FROM
SNOWFLAKE_SAMPLE_DATA.WEATHER.WEATHER_14_TOTAL
LIMIT 10;
// View all weather records for the past 2 weeks
SELECT
*
FROM
SNOWFLAKE_SAMPLE_DATA.WEATHER.WEATHER_14_TOTAL
WHERE
T >= DATEADD(DAY,-14,CURRENT_TIMESTAMP);
// ===========================================================================