//以 2018-01-22 1:56:55为例
convert(nvarchar(22),CreateDate,10)       => 2018-01-22
DATEPART(month,CreateDate)                    => 01
DATEPART(year,CreateDate)                     => 2018

//年
select datepart(YEAR,'2018-01-22')
select datepart(yyyy,'2018-01-22')
select datepart(yy,'2018-01-22')
//月
select datepart(MONTH,'2018-01-22')
select datepart(mm,'2018-01-22')
select datepart(m,'2018-01-22')
//日
select datepart(dd,'2018-01-22')
//季度
select datepart(qq,'2018-01-22')
//星期
select datepart(dw,'2018-01-22')
//一年中的第多少天
select datepart(dy,'2018-01-22')
//一年中的第多少周
select datepart(wk,'2018-01-22')


SELECT CONVERT(VARCHAR(22),GETDATE(),10)     --2018-01-22
SELECT CONVERT(VARCHAR(22),GETDATE(),221)   --01/22/2018

//按日分组: 2018-01-22
select convert(nvarchar(22),CreateDate,10) as Times,ISNULL(sum(Unit),0.0) as Drinking from pdt_Out
group by convert(nvarchar(22),CreateDate,10) 

//按月分组: 2018-01
select DATEPART(month,CreateDate) as Times,sum(Unit) as Totals from pdt_Out
group by DATEPART(month,CreateDate)

//按年分组: 2018
select DATEPART(year,CreateDate) as Times,sum(Unit) as Totals from pdt_Out
group by DATEPART(year,CreateDate)

澳门凯旋门注册网址,  SELECT DATE_澳门凯旋门游戏网址凯旋门074网址,FORMAT(f.registDate, ‘%Y-%m-%d’) AS
dayRegist,COUNT(f.flowingId) AS dayRegister
sql根据年月日查询注册数或者和值。sql根据年月日查询注册数或者和值。sql根据年月日查询注册数或者和值。  FROM shop_sql根据年月日查询注册数或者和值。invitation_flowerwater AS f
  GROUP BY dayRegist

//公司需要我做一个根据每天用户注册数量生成一个折现图,sql如下,
//亲测好用,只是如果某一天没有注册的话,就不会显示日期

 

相关文章