rampion
rampion

Reputation: 89043

SQL : Group All

I want to do the following pseudo-SQL:

SUM( SELECT a FROM tab WHERE b > 0);

This syntax doesn't work (at least not in sqlite), so I'm trying to figure out the proper phrasing.

SELECT SUM(a) FROM tab WHERE b > 0 GROUP BY (*); % nope
SELECT SUM(a) FROM tab WHERE b > 0 GROUP BY (1); % nope

Suggestions?

Upvotes: 2

Views: 190

Answers (2)

Zephyr
Zephyr

Reputation: 7823

What's wrong with just SELECT SUM(a) FROM tab WHERE b > 0?

Upvotes: 8

rampion
rampion

Reputation: 89043

 SELECT SUM(a) FROM tab GROUP BY (b > 0) HAVING (b > 0);

Upvotes: 0

Related Questions