sql server - Sum() column X, but add column Y only once
Posted
by Aseem Gautam
on Stack Overflow
See other posts from Stack Overflow
or by Aseem Gautam
Published on 2010-04-14T17:39:31Z
Indexed on
2010/04/14
17:43 UTC
Read the original article
Hit count: 349
sql-server
My table is like this
A X Y
1 2 3
1 4 3
2 9 1
2 7 1
What I want is to sum X column with Group By A but add Y only once. The values in column Y are always same for a specific A.
When I run this:
SELECT SUM(X) FROM TABLE GROUP BY A
It gives me: 12, 19. But I need 9, 18.
Thanks.
© Stack Overflow or respective owner