SELECT * FROM tb WHERE date = DATE_FORMAT('2008-01-20','%Y-%m');
select price from 一个表 where `date` <= DATE_FORMAT('2008-02-03','%Y-%m') order by `date` desc limit 1
你需要一个临时表,lsb,假设PRICE>0 字段: RH:存入2008-01-01到2008-12-01 price :内容为0select price from ( select * from tt union all select * from lsb) a where DATE_FORMAT(`date`,'%Y-%m')='2008-01' order by price desc limit 1
select t2.date,ifnull(t1.price,0) price from table2 t1 right join (select '2009-01-01' date) t2 on t1.date=date_format(t2.date,'%Y-%m')date price 2009-01-01 0 select t2.date,ifnull(t1.price,0) price from table2 t1 right join (select '2008-01-20' date) t2 on t1.date=date_format(t2.date,'%Y-%m')date price 2008-01-20 1.2
FROM tb
WHERE date = DATE_FORMAT('2008-01-20','%Y-%m');
from 一个表
where `date` <= DATE_FORMAT('2008-02-03','%Y-%m')
order by `date` desc
limit 1
字段:
RH:存入2008-01-01到2008-12-01
price :内容为0select price from (
select * from tt
union all
select * from lsb) a
where DATE_FORMAT(`date`,'%Y-%m')='2008-01'
order by price desc limit 1
select t2.date,ifnull(t1.price,0) price from table2 t1
right join
(select '2009-01-01' date) t2
on t1.date=date_format(t2.date,'%Y-%m')date price
2009-01-01 0
select t2.date,ifnull(t1.price,0) price from table2 t1
right join
(select '2008-01-20' date) t2
on t1.date=date_format(t2.date,'%Y-%m')date price
2008-01-20 1.2