開始使用免費開始

截斷

使用 trunc() 檢視《Fortune 500》公司屬性的分布。

記住,trunc() 會透過將較低位數替換為 0 來截斷數字:

trunc(value_to_truncate, places_to_truncate)

places_to_truncate 為負值時,表示要替換小數點左側的位數;為正值時,表示要保留小數點右側的位數。

本練習屬於課程

SQL 中的探索式資料分析

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- Truncate employees
SELECT ___(___, ___) AS employee_bin,
       -- Count number of companies with each truncated value
       ___
  FROM fortune500
 -- Use alias to group
 GROUP BY ___
 -- Use alias to order
 ORDER BY ___;
編輯並執行程式碼