-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to realized YOY/MOM on druid? #7928
Comments
This is not Druid specific (more like general SQL) but you would do: SELECT
COUNT(*) AS "BothMonths",
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00') AS "MonthX",
COUNT(*) FILTER(WHERE TIMESTAMP '2019-05-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00') AS "MonthY",
(
COUNT(*) FILTER(WHERE TIMESTAMP '2019-05-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00') -
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00')
) /
CAST(
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00')
AS DOUBLE)
* 100 AS "MonthOverMonth"
FROM "wikiticker"
WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00' Or (with a grouping): SELECT
"channel",
COUNT(*) AS "BothMonths",
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00') AS "MonthX",
COUNT(*) FILTER(WHERE TIMESTAMP '2019-05-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00') AS "MonthY",
(
COUNT(*) FILTER(WHERE TIMESTAMP '2019-05-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00') -
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00')
) /
CAST(
COUNT(*) FILTER(WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-05-01 00:00:00')
AS DOUBLE)
* 100 AS "MonthOverMonth"
FROM "wikiticker"
WHERE TIMESTAMP '2019-04-01 00:00:00' <= "__time" AND "__time" < TIMESTAMP '2019-06-01 00:00:00'
GROUP BY "channel"
ORDER BY "MonthOverMonth" DESC Obviously you do not need all those aggregates, I am just demonstrating. The idea is that you filter the overall query to both time intervals and then filter each aggregate to a specific interval |
thanks for you help,i try to accord to your method, it really succeeded. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to realize YOY or MOM on druid sql (or json file) ? just like this : can you help me ?
Month X – Month Y numbers
_______________________ x 100 = Percentage Growth
Month X
Year X – Year Y numbers
_______________________ x 100 = Percentage Growth
Year X number
The text was updated successfully, but these errors were encountered: