Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to write query for this table to separate dates with prouducre or table function
HTML
code        date          x            y
24       2010/2/14        2            3
26       2010/5/24        1            1
314      2010/6/14        3            1
30       2012/1/25        1            3
29       2012/3/11        2            1
28       2014/6/1         4            5
18       2014/7/20        8            1

i want this result

codecount         date     x        y
 2                2014     12       6 
 2                2012     3        4 
 3                2010     6        5   
Posted
Comments
Jörgen Andersson 29-Jan-15 13:25pm    
What server and version are you using?
saeed1364 30-Jan-15 0:57am    
sql 2012

1 solution

Assuming Microsoft SQL Server:
SQL
SELECT
  Count(1) As codecount,
  Year(date) As date,
  Sum(x) As x,
  Sum(y) As y
FROM
  YourTable
GROUP BY
  Year(date)
ORDER BY
  date DESC
;

http://sqlfiddle.com/#!3/925b0/2[^]
 
Share this answer
 

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