-
Notifications
You must be signed in to change notification settings - Fork 1
/
QueryJsonDataView.sql
37 lines (34 loc) · 987 Bytes
/
QueryJsonDataView.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
--
-- Zero To Snowflake in 90 Minuites
--
-- Query JSON Data via a view
--
--
-- Things to watch for:
-- 1. Is the json_table in the current schema?
-- 2. Are you ready for some really powerfull, cool SQL?!?!
--
-- Let's break down the projection:
-- <ColumnName>:<JSONPath>::<DataType> <alias>
-- Pretty simple. Pretty Powerful.
--
create or replace view vw_json as (
select
json_data:address.city::string city
, json_data:address.state::string state
, json_data:address.streetAddress::string address
, json_data:address.zip::string zip
, json_data:ip::string ip
, json_data:recDate::timestamp rec_date
, json_data:fname::string first_name
, json_data:lname::string lname
, json_data:comments::string comments
, list.value:cust_value::float cust_value
from json_table a,
lateral flatten(input => a.json_data:cust_values) list
);
--
-- Let's do some simple queries
--
select distinct state from vw_json limit 22;
select state, count(*) from vw_json group by 1 order by 2 desc;