Click here to Skip to main content
15,028,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
email id	transaction year	Net amount($)	Count of transaction
---------       ----------------        ------------     -------------------
ab@xy.com	2008	32	
ab@xy.com	2008	20	
ab@xy.com	2008	565	
ab@xy.com	2009	55	
ab@xy.com	2010	88	
ab@xy.com	2010	45	
ab@xy.com	2009	5	
cd@cv.com	2005	8	
cd@cv.com	2005	5	
cd@cv.com	2011	65	
cd@cv.com	2011	665	
cd@cv.com	2011	56	
cd@cv.com	2011	8	

Consider this table. I need the result as email id, transaction year, net amount and no of transaction in particular year in the below format.

For eg:
ab@xy.com      2008     617     3
ab@xy.com	2009	55      1
ab@xy.com      2010     133     2        etc...

How can I write query in SQL server? Please help.

Regards,
Shanif
Posted
Updated 4-May-13 1:12am
v3

1 solution

Try:
SQL
SELECT emailid, transyear, sum(transvalue), count(transvalue) FROM myTable GROUP BY emailID, transyear
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900