Skip to content

mrafayaleem/sql-snippets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQL Snippets

A curated collection of helpful SQL queries and functions, maintained by Count.

All contributions are very welcome - let's get useful SQL snippets out of Slack channels and Notion pages, and collect them as a community resource.

Snippet Databases

Analytics

Cohort analysis BigQuery
Cumulative distribution functions BigQuery Postgres MySQL SQL Server
Compound growth rates BigQuery SQL Server
Generate a binomial distribution BigQuery
Generate a uniform distribution BigQuery
Histogram bins BigQuery Snowflake Postgres
Median BigQuery
Median (UDF) BigQuery
Outlier detection: MAD method BigQuery
Outlier detection: Standard Deviation method BigQuery
Outlier detection: Z-score method BigQuery
Random Between BigQuery
Random sampling BigQuery Snowflake
Ranking BigQuery Snowflake Postgres
TF-IDF BigQuery

Arrays

Arrays to columns BigQuery Snowflake
Filtering arrays BigQuery Snowflake
Generating arrays BigQuery Snowflake
Get last array element BigQuery Postgres Snowflake
Reverse array Postgres
Transforming arrays BigQuery Snowflake
Least non-null value in array (UDF) BigQuery
Greatest/Least value in array BigQuery
Sort Array (UDF) Snowflake

Charts

Bar chart BigQuery Snowflake
Horizontal bar chart BigQuery Snowflake
Time series BigQuery Snowflake
100% stacked bar chart BigQuery Snowflake
Heat map BigQuery Snowflake
Stacked bar and line chart BigQuery Snowflake

Database metadata

Check if column exists in table SQL Server
Search for text in Stored Procedures SQL Server

Dates and times

Date/Time Formatting One Pager Postgres
Converting from strings BigQuery
Converting to strings BigQuery
Local Timezone to UTC BigQuery
Converting epoch/unix to timestamp Postgres
Generate timeseries Postgres
Last day of the month BigQuery
Last X days Postgres

Geography

Calculating the distance between two points BigQuery Snowflake

JSON

Parsing JSON strings BigQuery Postgres Snowflake

Regular & String expressions

Parsing URLs BigQuery Snowflake Postgres
Validating emails BigQuery Postgres
Extract repeating words BigQuery
Split on Uppercase characters BigQuery
Replace multple conditions BigQuery
CONCAT with NULLs BigQuery
Capitalize initial letters (UDF) MySQL
Concatenating strings SQL Server

Transformation

Pivot BigQuery Snowflake
Unpivoting / melting BigQuery Snowflake
Replace NULLs BigQuery Postgres Snowflake
Replace empty string with NULL BigQuery Postgres Snowflake
Counting NULLs BigQuery Postgres Snowflake
Splitting single columns into rows Postgres
Latest Row (deduplicate) BigQuery

Window functions

First row of each group BigQuery SQL Server
Moving averages BigQuery Snowflake Postgres
Running totals BigQuery Snowflake
Year-on-year changes BigQuery Snowflake
Creating equal-sized buckets Postgres

Other resources

About

A curated collection of helpful SQL queries and functions, maintained by Count.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published