易截截图软件、单文件、免安装、纯绿色、仅160KB

sql DATEPART()函数

cdate是datetime类型的字段
统计一年的如下
 select datepart(yy,cdate) as '月份',sum(cmoney) from consumption group by datepart(yy,cdate)
统计一月的如下
 select datepart(mm,cdate) as '月份',sum(cmoney) from consumption where datepart(yy,cdate)=2009 group by datepart(mm,cdate)
统计一周的如下
select DATEPART(wk,cdate) as '周', sum(cmoney) from consumption group by DATEPART(wk,cdate)
统计一天的如下
select DATEPART(dd,cdate) as '号', sum(cmoney) from consumption  where datepart(mm,cdate)=6  group by DATEPART(dd,cdate)
以上用到的就是“DATEPART()”函数。函数DATEPART()的参数是两个变量。第一个变量指定要抽取日期的哪一部分;第二个变量是实际的数据。
日期的各部分及其简写
日期部分           简写               值
year                yy                1753--9999
quarter             qq                1--4
month               mm                1--12
day of year         dy                1--366
day                 dd                1--31
week                wk              &n


相关文档:

SQL Server 中 int、bigint、smallint 和tinyint

使用整数数据的精确数字数据类型。
 bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。
              存储大小为 8 个字节。
 int 从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,64 ......

MySQL对标准SQL的扩展

MySQL服务器包含一些其他SQL DBMS中不具备的扩展。注意,如果使用了它们,将无法把代码移植到其他SQL服务器。在某些情况下,你可以编写包含MySQL扩展的代码,但仍保持其可移植性,方法是用“/*... */”注释掉这些扩展。MySQL服务器能够解析并执行注释中的代码,就像对待其他MySQL语句一样,但其他SQL服务器将忽略 ......

SQL中以日期为条件统计方法

 /*统计每天数据总量三种方法:
        select convert(char(10),happentime ,120) as date ,count(1) from table1
        group by convert(char(10),happentime ,120) order by date desc
       s ......

SQL Server使用Bulk Insert把一个文本导入到数据库

 
This is very common request recently – How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? Let us see the solution in quick steps.
CSV stands for Comma Separated Values, sometimes also called Co ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号