sql根据年月日查询注册数或者和值

2018-06-18 00:48:06来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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

  SELECT DATE_FORMAT(f.registDate, '%Y-%m-%d') AS dayRegist,COUNT(f.flowingId) AS dayRegister
  FROM shop_invitation_flowerwater AS f
  GROUP BY dayRegist


//
以 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)

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Can't connect to MySQL server (10065)

下一篇:mysql触发器