日期:2014-05-18 浏览次数:20707 次
--不知道是不是想要的 select count(1)-1, convert(varchar(7),dateadd(d,6,[date]),120) from [tb] group by convert(varchar(7),dateadd(d,6,[date]),120)
------解决方案--------------------
SELECT CONVERT(DATE,dd),SUM.... FROM [TB] WHERE DATEPART(dd,dd) = '26'
------解决方案--------------------
..........
26 就已经算下月了...
create table tb(dt datetime) insert into tb select '2010-06-26 23:02:00' insert into tb select '2010-06-27 23:02:00' insert into tb select '2010-06-28 23:02:00' insert into tb select '2010-06-29 23:02:00' insert into tb select '2010-06-30 23:02:00' insert into tb select '2010-07-01 23:02:00' insert into tb select '2010-07-02 23:02:00' insert into tb select '2010-07-03 23:02:00' insert into tb select '2010-07-04 23:02:00' insert into tb select '2010-07-05 23:02:00' insert into tb select '2010-07-06 23:02:00' insert into tb select '2010-07-07 23:02:00' insert into tb select '2010-07-08 23:02:00' insert into tb select '2010-07-09 23:02:00' insert into tb select '2010-07-10 23:02:00' insert into tb select '2010-07-11 23:02:00' insert into tb select '2010-07-12 23:02:00' insert into tb select '2010-07-13 23:02:00' insert into tb select '2010-07-14 23:02:00' insert into tb select '2010-07-15 23:02:00' insert into tb select '2010-07-16 23:02:00' insert into tb select '2010-07-17 23:02:00' insert into tb select '2010-07-18 23:02:00' insert into tb select '2010-07-19 23:02:00' insert into tb select '2010-07-20 23:02:00' insert into tb select '2010-07-21 23:02:00' insert into tb select '2010-07-22 23:02:00' insert into tb select '2010-07-23 23:02:00' insert into tb select '2010-07-24 23:02:00' insert into tb select '2010-07-25 23:02:00' insert into tb select '2010-07-26 23:02:00' insert into tb select '2010-07-27 23:02:00' insert into tb select '2010-07-28 23:02:00' insert into tb select '2010-07-29 23:02:00' insert into tb select '2010-07-30 23:02:00' insert into tb select '2010-07-31 23:02:00' insert into tb select '2010-08-01 23:02:00' insert into tb select '2010-08-02 23:02:00' insert into tb select '2010-08-03 23:0