SQL
Here are a few of my favorite SQL queries.
/* Find what tables are in a Postgre SQL Database */
SELECT * FROM pg_catalog.pg_tables;
/* Churn Rate */

/* Churn rate SQL Query – note you must fill in your own column and table names */
SELECT COUNT(DISTINCT user_id) AS enrollments, COUNT(CASE WHEN strftime("%m", cancel_date) = '03' THEN user_id END) AS march_cancellations, ROUND(100.0 * COUNT(CASE WHEN strftime("%m", cancel_date) = '03' THEN user_id END) / COUNT(DISTINCT user_id)) AS churn_rate FROM pro_users WHERE signup_date < '2017-04-01' AND ( (cancel_date IS NULL) OR (cancel_date > '2017-03-01') );
/* Select the count of a unique value in a table */
SELECT COUNT(DISTINCT column_name)
as what_you_want_to_call_it
FROM table_name;