CONNECT:
jonathan AT jonmaas DOT com +1-310-500-5841

SQL

I keep an Excel file of SQL queries here.

Below are also 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;

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google