views:

35

answers:

2
+1  Q: 

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?

A: 
 SELECT SUM(a) FROM tab GROUP BY (b > 0) HAVING (b > 0);
rampion
+7  A: 

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

Noel Abrahams
Nothing. Nothing at all.
rampion