All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
一个表,有金额,有日期,如何按月统计金额_[SQL Server教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/3 6:41:16 Browse times: 318 Comment times: 0

一个表,有金额,有日期,如何按月统计金额_[SQL Server教程]


Head photo

Go homepage
Upload pictures
Write articles

一个表,有金额,有日期,如何按月统计金额_[SQL Server教程]

在MS SQL SERVER中,按年、月、日统计:
按年统计
select year(销售日期)as 年份,sum(金额) as 总收入 from 图书销售表 group by year(销售日期)
按月统计
select month(销售日期)as 月份,sum(金额) as 总收入 from 图书销售表 where YEAR(销售日期)='2007' group by month(销售日期)
按日统计
select day(销售日期)as "按日统计",sum(金额) as 总收入 from 图书销售表 where year(销售日期)='2007' and month(销售日期)='1' group by day(销售日期)
--------------------------------------------------------------
CONVERT
将某种数据类型的表达式显式转换为另一种数据类型。
使用 CONVERT:
CONVERT (data_type[(length)], expression [, style])
参数
expression

是任何有效的 Microsoft® SQL Server™ 表达式。有关更多信息,请参见表达式。

data_type

目标系统所提供的数据类型,包括 bigint 和 sql_variant。不能使用用户定义的数据类型。有关可用的数据类型的更多信息,请参见数据类型。

length

nchar、nvarchar、char、varchar、binary 或 varbinary 数据类型的可选参数。

style

日期格式样式,借以将 datetime 或 smalldatetime 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型);或者字符串格式样式,借以将 float、real、money 或 smallmoney 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型)。

SQL Server 支持使用科威特算法的阿拉伯样式中的数据格式。

在表中,左侧的两列表示将 datetime 或 smalldatetime 转换为字符数据的 style 值。给 style 值加 100,可获得包括世纪数位的四位年份 (yyyy)。

不带世纪数位 (yy) 带世纪数位 (yyyy)
标准
输入/输出**
- 0 或 100 (*) 默认值 mon dd yyyy hh:miAM(或 PM)
1 101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*) 默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*) 欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm(24h)
- 20 或 120 (*) ODBC 规范 yyyy-mm-dd hh:mm:ss[.fff]
- 21 或 121 (*) ODBC 规范(带毫秒) yyyy-mm-dd hh:mm:ss[.fff]
- 126(***) ISO8601 yyyy-mm-dd Thh:mm:ss:mmm(不含空格)
- 130* 科威特 dd mon yyyy hh:mi:ss:mmmAM
- 131* 科威特 dd/mm/yy hh:mi:ss:mmmAM


* 默认值(style 0 或 100、9 或 109、13 或 113、20 或 120、21 或 121)始终返回世纪数位 (yyyy)。
======================================================================
ISNULL
使用指定的替换值替换 NULL。

语法
ISNULL ( check_expression , replacement_value )

参数
check_expression

将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。

replacement_value

在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。

返回类型
返回与 check_expression 相同的类型。

注释
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。

来源:网络





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.