Reputation: 487
I am computing current positions by summing historical transactions, using
SELECT pairID, instrumentID, Sum(sharesTraded)
FROM cef_schema.pairadj_table
GROUP BY pairID, instrumentID ORDER BY pairID;
This works fine, but produces responses for every pair even if the current position (sum of sharesTraded) is 0. I would prefer to omit these, but get an error if I try to restrict the SELECT with WHERE Sum(sharesTraded)!=0
.
Is there some way to restrict the results to non-zero sums?
Upvotes: 0
Views: 37
Reputation: 73251
You can use HAVING
:
SELECT pairID, instrumentID, Sum(sharesTraded) as sharesTradedSum
FROM cef_schema.pairadj_table
GROUP BY pairID, instrumentID
HAVING sharesTradedSum > 0
ORDER BY pairID
Upvotes: 4