SQL語句技巧:按月統(tǒng)計(jì)數(shù)據(jù)
更新時(shí)間:2006年08月24日 00:00:00 作者:
表結(jié)構(gòu)如下:
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
求一個(gè)SQL寫法,將每個(gè)月的數(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
求一個(gè)SQL寫法,將每個(gè)月的數(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
相關(guān)文章
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í)候?yàn)榱丝紤]數(shù)據(jù)安全我們都會(huì)備份數(shù)據(jù)庫,sqlserver的備份格式一般都是bak結(jié)尾的,但覆蓋時(shí)容易出問題,這里簡單介紹下,需要的朋友可以參考下2013-08-08SQL Server 樹形表非循環(huán)遞歸查詢的實(shí)例詳解
這篇文章主要介紹了SQL Server 樹形表非循環(huán)遞歸查詢的實(shí)例詳解的相關(guān)資料,本文介紹的非常詳細(xì)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10sqlserver 中時(shí)間為空的處理小結(jié)
sql server中常常需要使用DateTime類型的字段。當(dāng)此類型字段值為空時(shí),常常出現(xiàn)各種異常2011-10-10sqlserver中比較一個(gè)字符串中是否含含另一個(gè)字符串中的一個(gè)字符
sql中比較一個(gè)字符串中是否含有另一個(gè)字符串中的一個(gè)字符的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-09-09