MySQL查询最后7天的数据

MySql 码拜 8年前 (2016-02-03) 850次浏览
本人新手,半路出家需要用到MySQL,查询最后7天的数据(不是最近)
数据表tablet123
数据:
CREATE TABLE `tablet123` (
`id` int(11) NOT NULL,
`date` varchar(20) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL,
`description` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
请高手们帮看下,谢谢!
解决方案

80

— 最后日期-6 的
select * from tablet123 where cast(date as date) >=(
select max(cast(date as date))-6 from tablet123 )
— 最后 7 天有数据的
select * from tablet123 where cast(date as date) in (
select distinct cast(date as date) from tablet123 order by cast(date as date) desc limit 7)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明MySQL查询最后7天的数据
喜欢 (0)
[1034331897@qq.com]
分享 (0)