Skip to content

Instantly share code, notes, and snippets.

View lfy79001's full-sized avatar

Fangyu Lei lfy79001

View GitHub Profile
WITH bicycle_rentals AS (
SELECT
COUNT(starttime) as num_trips,
EXTRACT(DATE from starttime) as trip_date
FROM `bigquery-public-data.new_york_citibike.citibike_trips`
GROUP BY trip_date
),
rainy_days AS
(
DECLARE
my_drug_list ARRAY<STRING>;
SET
my_drug_list = [ 'Premarin',
'Calcium disodium versenate',
'Keytruda',
'Vioxx',
'Humira' ];
SELECT
id AS drug_id,
SELECT
associations.targetId AS target_id,
targets.approvedSymbol AS target_approved_symbol,
associations.diseaseId AS disease_id,
diseases.name AS disease_name,
associations.score AS overall_association_score
FROM
`open-targets-prod.platform.associationByOverallDirect` AS associations
JOIN
`open-targets-prod.platform.diseases` AS diseases
SELECT
game_clock,
SUM(
CASE
WHEN team_name = 'Wildcats' THEN points_scored
END
) OVER(ORDER BY timestamp ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS wildcats_score,
SUM(
CASE
WITH quantiles AS (
SELECT APPROX_QUANTILES(LOG10(latency), 50) AS timearray
FROM `cloud-datalab-samples.httplogs.logs_20140615`
WHERE latency <> 0
)
select row_number() over(order by time) as percentile, time from quantiles cross join unnest(quantiles.timearray) as time
order by percentile
SELECT
genex.case_barcode AS case_barcode,
genex.sample_barcode AS sample_barcode,
genex.aliquot_barcode AS aliquot_barcode,
genex.HGNC_gene_symbol AS HGNC_gene_symbol,
clinical_info.Variant_Type AS Variant_Type,
genex.gene_id AS gene_id,
genex.normalized_count AS normalized_count,
genex.project_short_name AS project_short_name,
clinical_info.demo__gender AS gender,
SELECT
case_list.case_barcode AS case_barcode,
case_list.Variant_Type AS Variant_Type,
clinical.demo__gender,
clinical.demo__vital_status,
clinical.demo__days_to_death
FROM
/* this will get the unique list of cases having the TP53 gene mutation in BRCA cases*/
( SELECT
mutation.case_barcode,
SELECT
age.country_name,
SUM(age.population) AS under_25,
pop.midyear_population AS total,
ROUND((SUM(age.population) / pop.midyear_population) * 100,2) AS pct_under_25
FROM (
SELECT country_name, population, country_code
FROM `bigquery-public-data.census_bureau_international.midyear_population_agespecific`
WHERE year =2017 AND age < 25) age
INNER JOIN (
SELECT
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'board') AS board_type,
AVG((SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'value')) AS avg_score
FROM `firebase-public-project.analytics_153293282.events_20180915`
WHERE event_name = "level_complete_quickplay"
GROUP BY board_type
WITH analytics_data AS (
SELECT user_pseudo_id, event_timestamp, event_name,
app_info.version AS app_version, -- This is new!
UNIX_MICROS(TIMESTAMP("2018-09-01 00:00:00", "+8:00")) AS start_day,
3600*1000*1000*24*7 AS one_week_micros
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _table_suffix BETWEEN '20180901' AND '20180930'
)
SELECT week_0_cohort / week_0_cohort AS week_0_pct,