Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

sql SUM question

$
0
0

I have a table named Trans, and that is the data contained.

Customer Product Ordered
C1            a            2
C2            b            1
C3            a            1
C1            a            2


I wonder a ordered total summary about product 'a' for every single customer, and I use this query,

SELECT
Trans.Customer,
SUM(Trans.Ordered) AS OrderedTotal
FROM Trans
WHERE Product = a
GROUP BY Trans.Customer

So I get this

Customer  OrderedTotal
C1             4
C3             1

But the query above can't return the result like this, so is it possible to write a query that let customer 'C2' in the final result?

Customer  OrderedTotal
C1             4
C2             0
C3             1

Thanks, everyone.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>