SQL語句技巧:按月統(tǒng)計數(shù)據(jù)
更新時間:2006年08月24日 00:00:00 作者:
表結構如下:
qty date
----------------------------------------------
13 2005/01/17
15 2005/01/19
3 2005/01/25
105 2005/01/27
1 2005/01/31
352 2005/02/03
12 2005/02/04
255 2005/02/07
6 2005/02/18
1 2005/02/19
28 2005/02/21
1 2005/02/22
394 2005/02/23
359 2005/02/24
313 2005/02/25
325 2005/02/26
544 2005/02/27
68 2005/02/28
2 2005/03/01
求一個SQL寫法,將每個月的數(shù)量求和,
如:
qry date
137 2005/01
?? 2005/02
?? 2005/03
SQL語句如下:
select sum(qty), datename(year, date) as year, datename(month, date) as month
from table
group by year, month
qty date
----------------------------------------------
13 2005/01/17
15 2005/01/19
3 2005/01/25
105 2005/01/27
1 2005/01/31
352 2005/02/03
12 2005/02/04
255 2005/02/07
6 2005/02/18
1 2005/02/19
28 2005/02/21
1 2005/02/22
394 2005/02/23
359 2005/02/24
313 2005/02/25
325 2005/02/26
544 2005/02/27
68 2005/02/28
2 2005/03/01
求一個SQL寫法,將每個月的數(shù)量求和,
如:
qry date
137 2005/01
?? 2005/02
?? 2005/03
SQL語句如下:
select sum(qty), datename(year, date) as year, datename(month, date) as month
from table
group by year, month
相關文章
sql server 2012 備份集中的數(shù)據(jù)庫備份與現(xiàn)有的xxx數(shù)據(jù)庫不同
這篇文章主要介紹了sql server 2012 備份集中的數(shù)據(jù)庫備份與現(xiàn)有的xxx數(shù)據(jù)庫不同,需要的朋友可以參考下2016-07-07SQLSERVER數(shù)據(jù)庫備份后無法還原的解決辦法
有時候為了考慮數(shù)據(jù)安全我們都會備份數(shù)據(jù)庫,sqlserver的備份格式一般都是bak結尾的,但覆蓋時容易出問題,這里簡單介紹下,需要的朋友可以參考下2013-08-08SQL Server 樹形表非循環(huán)遞歸查詢的實例詳解
這篇文章主要介紹了SQL Server 樹形表非循環(huán)遞歸查詢的實例詳解的相關資料,本文介紹的非常詳細具有參考借鑒價值,需要的朋友可以參考下2016-10-10sqlserver中比較一個字符串中是否含含另一個字符串中的一個字符
sql中比較一個字符串中是否含有另一個字符串中的一個字符的實現(xiàn)代碼,需要的朋友可以參考下。2010-09-09