MySQL查询最近一周(最近7天)数据
2018-08-13 07:38:11来源:博客园 阅读 ()
参考:https://blog.csdn.net/ouyang111222/article/details/77638826
-表结构
-
CREATE TABLE `zk_score` ( `id` varchar(255) NOT NULL COMMENT '评分表', `name` varchar(255) DEFAULT NULL COMMENT '机构名称', `totalscr` varchar(255) DEFAULT NULL COMMENT '综合得分', `unfiorm` varchar(255) DEFAULT NULL COMMENT '一致性', `complete` varchar(255) DEFAULT NULL COMMENT '完整性', `standard` varchar(255) DEFAULT NULL COMMENT '规范性', `timely` varchar(255) DEFAULT NULL COMMENT '及时性', `rank` varchar(255) DEFAULT NULL COMMENT '排名', `createtime` varchar(255) DEFAULT NULL COMMENT '更新时间', `status` varchar(255) DEFAULT NULL COMMENT '状态', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
-表数据
-
-SQL
-
select a.click_date as datetime, ifnull(b.totalscr,0) as totalscr, ifnull(b.standard,0) as standard, ifnull(b.complete,0) as complete, ifnull(b.unfiorm,0) as unfiorm, ifnull(b.timely,0) as timely from ( SELECT curdate() as click_date union all SELECT date_sub(curdate(), interval 1 day) as click_date union all SELECT date_sub(curdate(), interval 2 day) as click_date union all SELECT date_sub(curdate(), interval 3 day) as click_date union all SELECT date_sub(curdate(), interval 4 day) as click_date union all SELECT date_sub(curdate(), interval 5 day) as click_date union all SELECT date_sub(curdate(), interval 6 day) as click_date ) a left join ( select date(createtime) as datetime, AVG(totalscr) totalscr, AVG(standard) standard, AVG(complete) complete, AVG(unfiorm) unfiorm, AVG(timely) timely from zk_score group by date(createtime) ) b on a.click_date = b.datetime ORDER BY a.click_date ASC;
-查询结果
-
-获取近7天另一种sql
-
SELECT @num := @num + 1, date_format( date_sub( curdate()+1, INTERVAL @num DAY ), '%Y-%m-%d' ) AS date FROM zk_monit, ( SELECT @num := 0 ) t WHERE date_sub( curdate()+1, INTERVAL @num DAY ) <= date_format( curdate()+1, '%Y-%m-%d' ) and @num <7 ORDER BY date DESC;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:java-并发编程
- JSP+SSH+Mysql+DBCP实现的租车系统 2020-06-09
- JSP+Structs+JDBC+mysql实现的诚欣电子商城 2020-06-08
- java实现分页查询 2020-06-05
- Java高级实战Maven+JSP+SSM+Mysql实现的音乐网站,70%人不会 2020-06-04
- Maven+JSP+SSM+Mysql实现的音乐网站 2020-06-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash