Jake Marcotte
04/24/2023, 5:48 PM# Desired: We want to find the month Ratio that is essentially number of days in date range / 30.437 (average number of days in a month)
# We apply this ratio to a db-stored value that represents our "monthly" retainer
Jake Marcotte
04/24/2023, 5:58 PMIvana Gasparekova
04/24/2023, 6:34 PMJake Marcotte
04/24/2023, 6:45 PMIvana Gasparekova
04/24/2023, 6:46 PMVojtech Tollar
04/24/2023, 7:57 PMSELECT DATETIME_DIFF(
MIN({label/day.day}),
MAX({label/day.day}),
DAY) / 30.437
BY ALL OTHER
USING {label/business_id}
The BY ALL OTHER
clause makes it so the ratio will be the same for all rows.
Alternative form:
SELECT DATETIME_DIFF(
MIN({label/day.day}, {label/business_id}),
MAX({label/day.day}, {label/business_id}),
DAY) / 30.437
BY ALL OTHER
I hope this helpsJake Marcotte
04/24/2023, 8:21 PM