Skip to content

Instantly share code, notes, and snippets.

View paslandau's full-sized avatar
💭
¯\_(ツ)_/¯

Pascal Landau paslandau

💭
¯\_(ツ)_/¯
View GitHub Profile
@paslandau
paslandau / calculate-median-bigquery-example.sql
Created June 20, 2020 15:19
Example: Calculate the MEDIAN in BigQuery
# Calculate the MEDIAN in BigQuery; standard-sql; 2020-06-20
# @see http://www.pascallandau.com/bigquery-snippets/calculate-median/
WITH data as (
SELECT
1 as id,
"2020-06-20" as day,
10 as quantity
UNION ALL SELECT 2,"2020-06-20", 15
UNION ALL SELECT 1,"2020-06-21",5
UNION ALL SELECT 2,"2020-06-21",10
@paslandau
paslandau / bigquery-extract-url-parameters-array.sql
Last active May 16, 2023 06:09
Extract query parameters from a URL as ARRAY in BigQuery
#standardSQL
# Extract query parameters from a URL as ARRAY in BigQuery; standard-sql; 2018-04-08
# @see http://www.pascallandau.com/bigquery-snippets/extract-url-parameters-array/
WITH examples AS (
SELECT 1 AS id,
'?foo=bar' AS query,
'simple' AS description
UNION ALL SELECT 2, '?foo=bar&bar=baz', 'multiple params'
UNION ALL SELECT 3, '?foo[]=bar&foo[]=baz', 'arrays'
UNION ALL SELECT 4, '', 'no query'
@paslandau
paslandau / mysql2csv
Last active February 15, 2024 16:27
Helper command to export data for an arbitrary mysql query into a CSV file.
#!/usr/bin/env php
<?php
$intro = <<<TEXT
Helper command to export data for an arbitrary mysql query into a CSV file.
Especially helpful if the use of "SELECT ... INTO OUTFILE" is not an option, e.g.
because the mysql server is running on a remote host.
Usage example:
./mysql2csv --file="/tmp/result.csv" --query='SELECT 1 as foo, 2 as bar;' --user="username" --password="password"