{
"Имя": "Валентин",
"Фамилия": "Сикорски",
"Адрес": {
"Улица": "Проспект Мира 12, кв.54",
"Город": "Ленинград",
"Почтовый код": 143321
},
"Номер телефона": [
"8 800 975 4142", "+7 455 011 5575"
],
"Автомобиль": {
"Марка" : "Ауди",
"Модель" : "RS 7"
}
}
CREATE OR REPLACE TABLE business-metric.project.table2
(id INT64, clients JSON)
INSERT INTO business-metric.project.table2 VALUES
(1, JSON """{
"name": "Zik",
"street": "Проспект Мира 23, кв. 112",
"city": "Kyiv",
"post code" : 314564,
"phone_number" : "8 800 942 2121",
"items": [
{"product": "Компьютер", "price": 44999},
{"product": "Смартфон", "price": 19999}
]
}"""),
(2, JSON """{
"name": "Marya",
"street": "Московское ш. 13, кв. 21",
"city": "Moscow",
"post code" : 101000,
"phone_number" : "+7 (500) 554 2154",
"items": [
{"product": "Смартфон", "price": 12359}
]
}"""),
(3, JSON """{
"name": "Dmitriy",
"street":"Коммунистов 3б, кв. 3",
"city": "Moscow",
"post code" : 101000,
"phone_number" : "8 (800) 322 7311",
"items": [
{"product": "Телевизор", "price": 22999},
{"product": "Холодильник", "price": 13999},
{"product": "Чайник", "price": 3599}
]
}""")
[
{
"id": "1",
"first_name": "Annya",
"last_name": "Krid",
"dob": "1995-02-10",
"addresses": [
{
"status": "current",
"address": "123 First Avenue",
"city": "Los Angeles",
"zip": "11111"
},
{
"status": "previous",
"address": "456 Main Street",
"city": "New York",
"zip": "22222"
}
]
},
{
"id": "2",
"first_name": "Will",
"last_name": "Torw",
"dob": "1993-11-22",
"addresses": [
{
"status": "current",
"address": "789 Any Avenue",
"city": "New York",
"zip": "33333"
},
{
"status": "previous",
"address": "321 Main Street",
"city": "Chicago",
"zip": "44444"
}
]
}
]
{"id":"1","first_name":"Annya","last_name":"Krid","dob":"1995-02-10","addresses":[{"status":"current","address":"123 First Avenue","city":"Los Angeles","zip":"11111"},{"status":"previous","address":"456 Main Street","city":"New York","zip":"22222"}]}
{"id":"2","first_name":"Will","last_name":"Torw","dob":"1993-11-22","addresses":[{"status":"current","address":"789 Any Avenue","city":"New York","zip":"33333"},{"status":"previous","address":"321 Main Street","city":"Chicago","zip":"44444"}]}
{"id":"1","first_name":"Annya","last_name":"Krid", ...
{"id":"2","first_name":"Will","last_name":"Torw", ...
select id, first_name, last_name, dob, address
from `business-metric.project.table3`,
UNNEST (addresses) as address
select id, clients.name from `business-metric.project.table2`
SELECT
id,clients.name,
(clients['post code']) as post_code
FROM
`business-metric.project.table2`
SELECT
id,clients.name,
clients.items[0] as first_product
FROM
`business-metric.project.table2`
SELECT
id,
clients.name,
clients.street,
clients.phone_number,
clients.items
FROM
`business-metric.project.table2`
SELECT
id,
clients.name,
clients.items.product
FROM
`business-metric.project.table2`
SELECT
id,
JSON_VALUE (clients.name) as name
FROM
`business-metric.project.table2`
SELECT
id,
JSON_QUERY_ARRAY(clients.items) as items
FROM
`business-metric.project.table2`
SELECT
id,
JSON_VALUE (clients.name) as name,
JSON_VALUE (item.product) as items
FROM
`business-metric.project.table2`, UNNEST (JSON_QUERY_ARRAY(clients.items)) AS item
SELECT
id,
JSON_VALUE (clients.name) as name,
JSON_VALUE (clients.city) as city,
JSON_VALUE (clients['post code']) as post_code,
JSON_VALUE (clients.street) as street,
JSON_VALUE (clients.phone_number) as phone_number,
JSON_VALUE (item.product) as product,
JSON_VALUE (item.price) as price
FROM
`business-metric.project.table2`,
UNNEST (JSON_QUERY_ARRAY(clients.items)) AS item
SELECT
id,name,SUM(price) AS sum_price
FROM (
SELECT
id,
JSON_VALUE (clients.name) AS name,
JSON_VALUE (clients.city) AS city,
JSON_VALUE (clients['post code']) AS post_code,
JSON_VALUE (clients.street) AS street,
JSON_VALUE (clients.phone_number) AS phone_number,
JSON_VALUE (item.product) AS product,
CAST(JSON_VALUE (item.price) AS INT64) AS price
FROM
`business-metric.project.table2`,
UNNEST (JSON_QUERY_ARRAY(clients.items)) AS item )
GROUP BY name,id