Window

FIRST_VALUE

BigQueryBigQuery

Returns the first value in the window frame for each row.

Tipe hasil: Same as input expressionDiperbarui: 13 Jun 2026

Syntax

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
1SELECT
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
7FROM `project.dataset.stock_prices`;

Compares the current price against the opening price.

Hasil
symboldatepriceopening_pricechange_from_open
GOOG2024-01-011001000
GOOG2024-01-021051005
GOOG2024-01-031031003

First Purchase per Customer

SQL
1SELECT
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
6FROM `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.
Ngulik Langsung

Sudah paham FIRST_VALUE? Latih langsung di browser

Latihan interaktif, langsung di browser.

Latihan Langsung →