不太明白你的意思。我想這樣,按自然周來計(jì)算,一年共52周
創(chuàng)新互聯(lián)建站擁有網(wǎng)站維護(hù)技術(shù)和項(xiàng)目管理團(tuán)隊(duì),建立的售前、實(shí)施和售后服務(wù)體系,為客戶提供定制化的成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、成都天府聯(lián)通服務(wù)器托管解決方案。為客戶網(wǎng)站安全和日常運(yùn)維提供整體管家式外包優(yōu)質(zhì)服務(wù)。我們的網(wǎng)站維護(hù)服務(wù)覆蓋集團(tuán)企業(yè)、上市公司、外企網(wǎng)站、商城系統(tǒng)網(wǎng)站開發(fā)、政府網(wǎng)站等各類型客戶群體,為全球1000多家企業(yè)提供全方位網(wǎng)站維護(hù)、服務(wù)器維護(hù)解決方案。
select DATEPART(YEAR,[時(shí)間字段])*100+DATEPART(MONTH,[時(shí)間字段]),datepart(week,[時(shí)間字段]),SUM([數(shù)量]) from 表名
group by DATEPART(YEAR,[時(shí)間字段])*100+DATEPART(MONTH,[時(shí)間字段]),datepart(week,[時(shí)間字段])
月
SELECT
MONTH( date )
SUM ( sale )
FROM
表
GROUP BY
MONTH( date );
周
SELECT
WEEK ( date )
SUM ( sale )
FROM
表
GROUP BY
WEEK( date );
注:
MONTH 函數(shù), 取得 參數(shù)日期的 月
WEEK 函數(shù), 取得 參數(shù)日期的 周
( 按照老外的 算法。 一周的開始, 是從周日開始的 )
假設(shè)你的表為 ta 日期字段是 dt
那么,以 2015-01-01為起始日,每5天累總計(jì)數(shù)為:
select datediff(dt, '2015-01-01') div 5 as d5 , count(*)
from ta
group by (datediff(dt, '2015-01-01') div 5)
select * from wap_content where week(created_at) = week(now)
如果要嚴(yán)格要求是某一年的,那可以這樣
查詢一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查詢一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) = date(column_time);
查詢一個(gè)月:
select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) =
date(column_time);
查詢一年:
select * from table ?where DATE_SUB(CURDATE(), INTERVAL 1 YEAR) = date(column_time);
擴(kuò)展資料
mysql查詢最近7天的數(shù)據(jù):
1,(以當(dāng)天為起點(diǎn))
SELECT * FROM tb_equity e where DATE_SUB(CURDATE(), INTERVAL 6 DAY) =
date(createdate)
2,(以數(shù)據(jù)庫最新的時(shí)間最為最近的一天)
SELECT * FROM tb_equity e where createdate DATE_ADD((select createdate from tb_equity
ORDER BY createdate DESC limit 1) ,INTERVAL -7 day)
and (select createdate from tb_equity ORDER BY createdate DESC limit 1) = createdate
3,sql查詢表中的重復(fù)數(shù)據(jù)
select * from 表名 where 字段名 in (select 字段名 from 表名 group by 字段名 HAVING COUNT(*)
1) order by 表名
參考資料來源:百度百科 - 結(jié)構(gòu)化查詢語言
參考資料來源:百度百科 - mySQL (關(guān)系型數(shù)據(jù)庫管理系統(tǒng))
參考資料來源:百度百科 - select (Linux 網(wǎng)絡(luò)編程)
以周一作為一周的開始, 使用mysql week行數(shù)模式5:
作為周劃分的標(biāo)準(zhǔn), 比如20170101是周天, week(20170101, 5) = 0,
分WEEK_IN_MONTH, 和WEEK_IN_YEAR兩種情況進(jìn)行分組:
WEEK_IN_YEAR:
#?by?sleest?2017/03/29?按每個(gè)日期所在一年中的第幾周分組匯總
SELECT?WEEK(MY_DATE,?5)+1?AS?WEEK_OF_YEAR,?COUNT(1)?AS?COUNT,
GROUP_CONCAT(MY_DATE)?AS?INCLUDE_DATE
FROM?(SELECT?'2017-01-01'?AS?MY_DATE
UNION?ALL
SELECT?'2017-02-08'?
UNION?ALL
SELECT?'2017-02-03'?
UNION?ALL
SELECT?'2017-02-01'?
UNION?ALL
SELECT?'2017-01-21')?TMP
GROUP?BY?WEEK(MY_DATE,?5)?+?1;
結(jié)果:
WEEK_IN_MONTH:
#?by?sleest?2017/03/29?按每個(gè)日期所在每個(gè)月的第幾周分組匯總
SELECT?WEEK(MY_DATE,?5)?-?WEEK(DATE_SUB(MY_DATE,?INTERVAL?DAYOFMONTH(MY_DATE)?-?1?DAY),?5)?+?1?AS?WEEK_OF_MONTH,?
COUNT(1)?AS?COUNT,
GROUP_CONCAT(MY_DATE)?AS?INCLUDE_DATE
FROM?(SELECT?'2017-01-01'?AS?MY_DATE
UNION?ALL
SELECT?'2017-02-08'?
UNION?ALL
SELECT?'2017-02-03'?
UNION?ALL
SELECT?'2017-02-01'?
UNION?ALL
SELECT?'2017-01-21')?TMP
GROUP?BY?WEEK(MY_DATE,?5)?-?WEEK(DATE_SUB(MY_DATE,?INTERVAL?DAYOFMONTH(MY_DATE)?-?1?DAY),?5)?+?1
結(jié)果:
select * from 表名 where 時(shí)間字段名=date_sub(curdate(),interval 7 day);
近一周的數(shù)據(jù)
select DATE_FORMAT(d.dateType,'%Y%u') as '年份周數(shù)',d.shuzhi,d.type
from 'date_dealsheetpage'd
order by d.dateType
查詢每周
select SUBSTRING(d.dateType, 1,7) as '年份月份',d.shuzhi,d.type
from 'date_dealsheetpage'd
查詢每月