[英]In MySQL, how to select data based on date?
I need to get record based on date but I got stuck.我需要根据日期获取记录,但我被卡住了。
rate applicable_date
12 01/01/2001
13.5 01/05/2005
17.9 07/11/2017
I need to get applicable rate based on applicable date.我需要根据适用日期获得适用费率。 I used below SQL:
我使用了以下 SQL:
Select rate from ratetable where applicable_date <=$date;
For $date = '12/02/2017'
;对于
$date = '12/02/2017'
;
It returns me 12
它返回给我
12
but for date 17/11/2017 it returns me all rates but I need only 17.9 latest one.但是对于 2017 年 17 月 11 日的日期,它会返回所有费率,但我只需要 17.9 最新的费率。
尝试执行以下查询
select rate from ratetable where applicable_date = $date
select rate
from ratetable
where applicable_date <=$date
order by desc
limit 1;
now it will return only 17.9现在它只会返回 17.9
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.