Snowflake में डेटा मैनिपुलेशन
Jake Roach
Field Data Engineer
सबक्वेरीज़ एक टूल हैं जिनसे एक क्वेरी का परिणाम दूसरी क्वेरी में इस्तेमाल होता है.
$$
$$
FROM ( ... ) या WHERE ... IN ( ... )

SELECT
...
-- Pull from query, not from a table
FROM (
-- Create a result set that will
-- be used by the main query
SELECT
<fields>
FROM <table>
WHERE ...
);
टेबल से सीधे लेने के बजाय किसी दूसरी क्वेरी के परिणाम से डेटा प्राप्त करें.
$$
JOIN, WHERE, आदिSELECT
month_num,
-- windchill - temperature has to be used twice here. What if this changes?
AVG(windchill - temperature) AS avg_differential
MIN(windchill - temperature) AS most_differential
FROM weather
WHERE
-- Filtering is taking place in the same query as aggregation/analysis
season = 'Winter' AND
temperature < 32
GROUP BY month_num;
-- Start with the subquery, then aggregateSELECT month_num, AVG(differential) AS avg_differential MIN(differential) AS most_differential FROM (SELECT month_num, windchill - temperature AS differential FROM weather WHERE season = 'Winter' AND temperature < 32) GROUP BY month_num;
| month_num | differential |
| --------- | ------------ |
| 12 | -12 |
| 1 | -3 |
| 1 | 0 |
| 2 | -7 |
| month_num | avg_differential | most_differential |
| --------- | ---------------- | ----------------- |
| 12 | -5.77 | -14 |
| 1 | -1.91 | -8 |
| 2 | -8.13 | -22 |
डेटा साफ होने पर विश्लेषण समझना और बदलना आसान हो जाता है.
...
-- Filter by records with a value in
-- the subquery result set
WHERE <field> IN (
SELECT <other-field> FROM ...
);
ट्रांसफॉर्म, फ़िल्टर, या डेटा मैनिपुलेट करते समय उपयोग के लिए एक छोटा परिणाम सेट बनाएँ.
$$
IN एक non-constant रिजल्ट सेट होंAVG, MAX, MIN, आदिSELECT
todays_date,
temperature,
status
FROM weather
WHERE todays_date IN ( -- Filter by all days with home games that were won
SELECT
game_date
FROM game_schedule
WHERE stadium = 'Home' AND did_win = TRUE
);

Snowflake में डेटा मैनिपुलेशन