sql array 数组基本用法(四)
生活随笔
收集整理的這篇文章主要介紹了
sql array 数组基本用法(四)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
查詢嵌套數組
SELECT "800M" AS race,[STRUCT("Rudisha" as name, [23.4, 26.3, 26.4, 26.1] as splits),STRUCT("Makhloufi" as name, [24.5, 25.4, 26.6, 26.1] as splits),STRUCT("Murphy" as name, [23.9, 26.0, 27.0, 26.0] as splits),STRUCT("Bosse" as name, [23.6, 26.2, 26.5, 27.1] as splits),STRUCT("Rotich" as name, [24.7, 25.6, 26.9, 26.4] as splits),STRUCT("Lewandowski" as name, [25.0, 25.7, 26.3, 27.2] as splits),STRUCT("Kipketer" as name, [23.2, 26.1, 27.3, 29.4] as splits),STRUCT("Berian" as name, [23.7, 26.1, 27.0, 29.3] as splits)]AS participants這是一行數據,查詢的時候需要把數據展開
WITH races AS (SELECT "800M" AS race,[STRUCT("Rudisha" as name, [23.4, 26.3, 26.4, 26.1] as splits),STRUCT("Makhloufi" as name, [24.5, 25.4, 26.6, 26.1] as splits),STRUCT("Murphy" as name, [23.9, 26.0, 27.0, 26.0] as splits),STRUCT("Bosse" as name, [23.6, 26.2, 26.5, 27.1] as splits),STRUCT("Rotich" as name, [24.7, 25.6, 26.9, 26.4] as splits),STRUCT("Lewandowski" as name, [25.0, 25.7, 26.3, 27.2] as splits),STRUCT("Kipketer" as name, [23.2, 26.1, 27.3, 29.4] as splits),STRUCT("Berian" as name, [23.7, 26.1, 27.0, 29.3] as splits)]AS participants) SELECTrace,participant FROM races r CROSS JOIN UNNEST(r.participants) as participant;| 800M | {Rudisha, [23.4, 26.3, 26.4, 26.1]} |
| 800M | {Makhloufi, [24.5, 25.4, 26.6, 26.1]} |
| 800M | {Murphy, [23.9, 26, 27, 26]} |
| 800M | {Bosse, [23.6, 26.2, 26.5, 27.1]} |
| 800M | {Rotich, [24.7, 25.6, 26.9, 26.4]} |
| 800M | {Lewandowski, [25, 25.7, 26.3, 27.2]} |
| 800M | {Kipketer, [23.2, 26.1, 27.3, 29.4]} |
| 800M | {Berian, [23.7, 26.1, 27, 29.3]} |
總結
以上是生活随笔為你收集整理的sql array 数组基本用法(四)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql array 数组基本用法(三)
- 下一篇: sql生成两列数据