Skip to content

Instantly share code, notes, and snippets.

@thomasthaddeus
Created August 4, 2022 04:47
Show Gist options
  • Save thomasthaddeus/6eb1bd56d9393ec9de99d1366b094656 to your computer and use it in GitHub Desktop.
Save thomasthaddeus/6eb1bd56d9393ec9de99d1366b094656 to your computer and use it in GitHub Desktop.
Queries to remember
SELECT purchase_id, DATE(purchase_date, '7 days')
FROM purchases;
SELECT STRFTIME('%H', purchase_date)
FROM purchases;
SELECT date, (CAST(high AS 'REAL') +
CAST(low as 'REAL')) / 2.0 AS 'average'
FROM weather
;
SELECT ROW_NUMBER()
OVER (
ORDER BY gross
) AS 'row_num', title, week, gross
FROM box_office;
SELECT title, week, gross,
SUM(gross) OVER (
PARTITION BY title
ORDER BY week
) AS 'running_total_gross'
FROM box_office;
@thomasthaddeus
Copy link
Author

SELECT strftime('%H',purchase_date) 
     AS 'Hour',
   COUNT(strftime('%H',purchase_date)) 
     AS 'Purchases'
FROM purchases 
GROUP BY 1 
ORDER BY 2 desc;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment