Advanced Functions + UDF + Partitioning

Function toolbox

Analytic / Window functions

-- Example: state별 최대 고용주 (2015), 동률 허용: RANK()
WITH base AS (
  SELECT
    ein, name, state,
    noemplyeesw3cnt AS num_emp
  FROM `bigquery-public-data.irs_990.irs_990_2015` a
  JOIN `bigquery-public-data.irs_990.irs_990_ein` b USING (ein)
)
SELECT *
FROM (
  SELECT
    ein, name, state, num_emp,
    RANK() OVER (PARTITION BY state ORDER BY num_emp DESC) AS r
  FROM base
)
WHERE r = 1
ORDER BY num_emp DESC;

UDF (User-Defined Functions)

Components