You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query - here sea-query does not support all I need - i.e. COUNT(DISTINCT a.b) -, and some stuff gets very tricky even with Expr::cust_with_exprs() etc.:
SELECT p.`year_month`,
COUNT(a.uid) AS all_activity,
IF(
LAG(p.`year_month`) OVER (ORDER BY p.`year_month`DESC) IS NULL,
NULL,
(COUNT(a.uid) / (LEAD(COUNT(a.uid)) OVER (ORDER BY p.`year_month`DESC)) -1) *100
) AS all_activity_change_percent,
COUNT(DISTINCT a.year_month_day) AS active_days,
IF(
LAG(p.`year_month`) OVER (ORDER BY p.`year_month`DESC) IS NULL,
NULL,
(COUNT(DISTINCT a.year_month_day) / (LEAD(COUNT(DISTINCT a.year_month_day)) OVER (ORDER BY p.`year_month`DESC)) -1) *100
) AS active_days_change_percent,
COUNT(DISTINCT a.person) AS active_personnel,
IF(
LAG(p.`year_month`) OVER (ORDER BY p.`year_month`DESC) IS NULL,
NULL,
(COUNT(DISTINCT a.person) / (LEAD(COUNT(DISTINCT a.person)) OVER (ORDER BY p.`year_month`DESC)) -1) *100
) AS active_personnel_change_percent
FROM (
SELECT DISTINCT`year_month`FROM tx_digibordauthentication_activity
ORDER BY`year_month`DESC
) p
LEFT JOIN tx_digibordauthentication_activity a
ONa.year_month=p.year_monthANDa.institution=2050GROUP BY p.`year_month`ORDER BY p.`year_month`DESC;
Proposed Solutions
Add Expr::count_distinct() and Func::count_distinct()
Additional Information
I am missing a few things here and I will open separate issues for these:
Ref:
Motivation
I am aggregating data and need to count not all rows, but merely distinct rows where some might be present multiple times.
My use case is this (MariaDB):
Table (just to give you context for the query further below - I am not currently looking to build this
CREATE TABLE
statement in sea-query):Query - here sea-query does not support all I need - i.e.
COUNT(DISTINCT a.b)
-, and some stuff gets very tricky even withExpr::cust_with_exprs()
etc.:Proposed Solutions
Add
Expr::count_distinct()
andFunc::count_distinct()
Additional Information
I am missing a few things here and I will open separate issues for these:
COUNT(DISTINCT <table-ref>)
SupportCOUNT(DISTINCT a.b)
#600IF(<cond>, <then-expr>, <else-expr>)
SupportIF(<cond>, <then-expr>, <else-expr>)
#602LAG(<expr>) OVER (<order-by>)
Support window functions likeLEAD(...) OVER (...)
andLAG(...) OVER (...)
(and others) #601LEAD(<expr>) OVER (<order-by>)
Support window functions likeLEAD(...) OVER (...)
andLAG(...) OVER (...)
(and others) #601The text was updated successfully, but these errors were encountered: