Snowflake 的資料型別與函式
Jake Roach
Field Data Engineer

比較運算子可用來比較或評估多個值
=, 兩個值是否為「相等」?!=, 兩個值是否「不相等」?<, 是否「小於」另一個值?>, 是否「大於」另一個值?<= 小於「或」等於>=, 大於「或」等於$$
回傳 `true` 或 `false`!
$$
1 = 1, -- true1 != 1, -- false1 < 2, -- true1 > 2, -- false1 <= 2, -- true2 >= 2 -- true... WHERE 1 = 1 -- Filter records
SELECT
<#> + <#>, -- 2 + 2 -> 4
<field> - <#>, -- 4 - 1 -> 3
<field> * <#>, -- 3 * 2 -> 6
<field> / <#>, -- 9 / 3 -> 3
...
# 與 field 的各種排列間進行運算算術運算子可對數值做「運算」
$$
+,加法-,減法*,乘法/,除法SELECT student_name, exam_score,exam_score + 10 AS add_points, -- Add 10 points to each student's gradeexam_score * curve AS curved, -- Curve the grade by 10%exam_score / 2 AS weighted -- Reduce the weight of the testFROM STUDENTS.grades;
student_name | exam_score | add_points | curved | weighted
-------------- | -------------- | ------------ | -------- | ----------
Ryan | 78 | 88 | 85.8 | 39
Tatiana | 89 | 99 | 97.9 | 44.5
Pankaj | 74 | 84 | 81.4 | 37

SELECT<1>,SUM(<field>), -- Returns the total of a columnAVG(<field>) -- Finds the average value of a columnFROM ...GROUP BY <1>;
「非聚合欄位」必須 GROUP BY!
GROUP BY ALLSELECT exam_name, SUM(correct_answers) AS total_correct_answers, -- Total # correct AVG(exam_score) AS avg_exam_score, -- Average exam scoreROUND(AVG(exam_score), 1) AS rounded_exam_score -- ROUND(<value>, <n>)FROM STUDENTS.grades GROUP BY exam_name; -- GROUP BY to aggregate records, otherwise error
ROUND() 需要要四捨五入的值,以及小數點後要保留的位數
exam_name | total_correct_answers | avg_exam_score | rounded_avg_exam_score
------------- | ----------------------- | ---------------- | ------------------------
Calculus I | 871 | 89.11111 | 89.1
Biology | 776 | 87.47777 | 87.5
English III | 541 | 91.33333 | 91.3
Python | 1179 | 92.78787 | 92.8
Finance | 349 | 96.14156 | 96.1
以上值使用下列方式產生:
SUM(correct_answers)AVG(exam_score)ROUND(AVG(exam_score), 2)Snowflake 的資料型別與函式