select datepart(dw,t),count(*) from a group by datepart(dw,t)
解决方案 »
- 请教一下UPDATE的问题
- Sql 插入触发器更新数据
- 专家帮忙,大数据量表建索引问题
- 2|3|5|6|13|12|7|16 ,如何查||间有2的数字的记录查出来,注意不能把12,122,22这样有2的记录的查出来!
- 救急 mysql 语句优化问题
- 高手快来:如何用Sql知道Northwind中有什么表?
- 安装sql server 2008 express版出现问题!
- 关于VFP的DBF文件与SQL-SERVER2000数据库文件之间导入和导出的解决办法
- 请教SQL语句,急~~~~~~,请给予帮助,谢谢!!!!!
- 一个关于ODBC连接SQL SERVER的问题,100分!
- 创建“允许为空,但不为空时不能重复”的约束
- 求助一个SQL语句问题!
返回代表指定日期的指定日期部分的整数。语法
DATEPART ( datepart , date ) 参数
datepart是指定应返回的日期部分的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。
日期部分 缩写
year yy, yyyy
quarter qq, q
month mm , m
dayofyear dy, y
day dd, d
week wk, ww
weekday dw
Hour hh
minute mi, n
second ss, s
millisecond ms weekday (dw) 日期部分返回对应于星期中的某天的数,例如:Sunday = 1、Saturday = 7。weekday 日期部分产生的数取决于 SET DATEFIRST 设定的值,此命令设定星期中的第一天。
insert @t select '2007-12-12'
insert @t select '2007-12-13'
insert @t select '2007-12-14'
insert @t select '2007-12-16'
insert @t select '2007-12-17'
insert @t select '2007-12-18'
insert @t select '2007-12-19'
insert @t select '2007-12-20'
insert @t select '2007-12-21'
insert @t select '2007-12-22'
insert @t select '2007-12-23'
insert @t select '2007-12-24'
insert @t select '2007-12-25'
insert @t select '2007-12-26'
insert @t select '2007-12-27'select weekday,count(*) as count
from
(
select datepart(weekday,date) as weekday
from @t
) a
group by weekday/*
weekday count
----------- -----------
1 2
2 2
3 2
4 3
5 3
6 2
7 1(所影响的行数为 7 行)
*/
insert @t select '2007-12-12'
insert @t select '2007-12-13'
insert @t select '2007-12-14'
insert @t select '2007-12-16'
insert @t select '2007-12-17'
insert @t select '2007-12-18'
insert @t select '2007-12-19'
insert @t select '2007-12-20'
insert @t select '2007-12-21'
insert @t select '2007-12-22'
insert @t select '2007-12-23'
insert @t select '2007-12-24'
insert @t select '2007-12-25'
insert @t select '2007-12-26'
insert @t select '2007-12-27'select weekday,count(*) as count
from
(
select '星期'+rtrim(datepart(weekday,date)) as weekday
from @t
) a
group by weekday/*
weekday count
---------------- -----------
星期1 2
星期2 2
星期3 2
星期4 3
星期5 3
星期6 2
星期7 1(所影响的行数为 7 行)
*/