如何获取此表的单独日期查询 [英] how get tihs query for this table separate dates

查看:76
本文介绍了如何获取此表的单独日期查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为此表编写查询以使用prouducre或table函数分隔日期

I try to write query for this table to separate dates with prouducre or table function

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   

推荐答案

假设Microsoft SQL Server:

Assuming Microsoft SQL Server:
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 [ ^ ]


这篇关于如何获取此表的单独日期查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆