Window
BigQuery
FIRST_VALUE
Returns the first value in the window frame for each row.
Tipe hasil:
Same as input expressionDiperbarui: 13 Jun 2026Syntax
SQL
FIRST_VALUE(expression) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [frame_clause])Parameter
expressionanywajib
Column or expression whose value is retrieved
PARTITION BYexpressionopsional
Divides data into groups
ORDER BYexpressionopsional
Determines the order for identifying the first value
Contoh Penggunaan
Opening Price per Stock
SQL
1 SELECT 2 symbol, 3 date, 4 price, 5 FIRST_VALUE(price) OVER (PARTITION BY symbol ORDER BY date) as opening_price, 6 price - FIRST_VALUE(price) OVER (PARTITION BY symbol ORDER BY date) as change_from_open 7 FROM `project.dataset.stock_prices`;
Compares the current price against the opening price.
Hasil
| symbol | date | price | opening_price | change_from_open |
|---|---|---|---|---|
| GOOG | 2024-01-01 | 100 | 100 | 0 |
| GOOG | 2024-01-02 | 105 | 100 | 5 |
| GOOG | 2024-01-03 | 103 | 100 | 3 |
First Purchase per Customer
SQL
1 SELECT 2 customer_id, 3 order_date, 4 amount, 5 FIRST_VALUE(order_date) OVER (PARTITION BY customer_id ORDER BY order_date) as first_order_date 6 FROM `project.dataset.orders`;
Retrieves the first order date for each customer.
Pertanyaan Umum tentang FIRST_VALUE
Apa itu fungsi FIRST_VALUE di BigQuery?
Returns the first value in the window frame for each row. Di BigQuery, fungsi FIRST_VALUE termasuk dalam kelompok fungsi yang sering digunakan untuk mengolah dan menganalisis data secara efisien.
Bagaimana cara menggunakan FIRST_VALUE di BigQuery?
Gunakan sintaks berikut: FIRST_VALUE(expression) OVER ([PARTITION BY partition_expression] ORDER BY sort_expression [frame_clause]). Pastikan argumen yang dimasukkan sudah sesuai dengan tipe data yang diharapkan.
Apa nilai yang dikembalikan oleh fungsi FIRST_VALUE?
Fungsi FIRST_VALUE mengembalikan nilai bertipe Same as input expression. Pastikan tipe data hasil sudah sesuai dengan kebutuhan query atau formula kamu. Jika input mengandung nilai NULL, perilaku fungsi dapat berbeda — selalu periksa dokumentasi untuk memastikan hasilnya sesuai ekspektasi.
Apa saja parameter fungsi FIRST_VALUE?
Fungsi ini memiliki 1 parameter wajib dan 2 parameter opsional. Parameter yang digunakan: expression (any, wajib): Column or expression whose value is retrieved; PARTITION BY (expression, opsional): Divides data into groups; ORDER BY (expression, opsional): Determines the order for identifying the first value.
Fungsi Terkait
Ngulik Langsung
Latihan Langsung →Sudah paham FIRST_VALUE? Latih langsung di browser
Latihan interaktif, langsung di browser.