Is there a N1QL aggregate that counts true values?

I’ve got a N1QL query with a number of columns similar to this:

 sum( case when lastSeen <= 600000 then 1 else 0 end ) as countLast10Min,

This may be a premature optimaztaion, but I was curious if there was an aggregate that would directly count true values. Along the lines of:

countTrue( lastSeen <= 600000 ) as countLast10Min,

Again, what I have in the first example works, I just wanted to make sure I wasn’t missing a simpler or more performant alternative.

1 Like

SQL Standard

COUNT(expr) — All non-MISSING, non-NULL values are counted
COUNTN(expr) — expr is numeric then only counted

In 7.0 Beta you can do (https://modern-sql.com/feature/filter)

SUM(<expression>) FILTER(WHERE <condition>)

2 Likes

@vsr1 thanks for the reply. Somehow I never got notified of it. It sounds like the short answer to my question is “no” but there’s some stuff coming in the 7.0 Beta that will help. I don’t know if the FILTER clause will actually improve performance or not.

1 Like