本人新手,半路出家需要用到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`)
请高手们帮看下,谢谢!
数据表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)
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)