十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
不太明白你的意思。我想这样,按自然周来计算,一年共52周
创新互联建站拥有网站维护技术和项目管理团队,建立的售前、实施和售后服务体系,为客户提供定制化的成都网站建设、网站建设、网站维护、成都天府联通服务器托管解决方案。为客户网站安全和日常运维提供整体管家式外包优质服务。我们的网站维护服务覆盖集团企业、上市公司、外企网站、商城系统网站开发、政府网站等各类型客户群体,为全球1000多家企业提供全方位网站维护、服务器维护解决方案。
select DATEPART(YEAR,[时间字段])*100+DATEPART(MONTH,[时间字段]),datepart(week,[时间字段]),SUM([数量]) from 表名
group by DATEPART(YEAR,[时间字段])*100+DATEPART(MONTH,[时间字段]),datepart(week,[时间字段])
月
SELECT
MONTH( date )
SUM ( sale )
FROM
表
GROUP BY
MONTH( date );
周
SELECT
WEEK ( date )
SUM ( sale )
FROM
表
GROUP BY
WEEK( date );
注:
MONTH 函数, 取得 参数日期的 月
WEEK 函数, 取得 参数日期的 周
( 按照老外的 算法。 一周的开始, 是从周日开始的 )
假设你的表为 ta 日期字段是 dt
那么,以 2015-01-01为起始日,每5天累总计数为:
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)
如果要严格要求是某一年的,那可以这样
查询一天:
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);
查询一个月:
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);
扩展资料
mysql查询最近7天的数据:
1,(以当天为起点)
SELECT * FROM tb_equity e where DATE_SUB(CURDATE(), INTERVAL 6 DAY) =
date(createdate)
2,(以数据库最新的时间最为最近的一天)
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查询表中的重复数据
select * from 表名 where 字段名 in (select 字段名 from 表名 group by 字段名 HAVING COUNT(*)
1) order by 表名
参考资料来源:百度百科 - 结构化查询语言
参考资料来源:百度百科 - mySQL (关系型数据库管理系统)
参考资料来源:百度百科 - select (Linux 网络编程)
以周一作为一周的开始, 使用mysql week行数模式5:
作为周划分的标准, 比如20170101是周天, week(20170101, 5) = 0,
分WEEK_IN_MONTH, 和WEEK_IN_YEAR两种情况进行分组:
WEEK_IN_YEAR:
# by sleest 2017/03/29 按每个日期所在一年中的第几周分组汇总
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;
结果:
WEEK_IN_MONTH:
# by sleest 2017/03/29 按每个日期所在每个月的第几周分组汇总
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
结果:
select * from 表名 where 时间字段名=date_sub(curdate(),interval 7 day);
近一周的数据
select DATE_FORMAT(d.dateType,'%Y%u') as '年份周数',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
查询每月