我有一个交易日期,我想获取小于或等于交易日期的最新生效日期的数据。
这是我的 table
transactiondate|effectivedate|unitprice
19-02-19 |01-01-19 | 36
19-02-19 |28-12-18 | 30
19-02-19 |15-12-18 | 20
这是我使用的查询
select A.unitprice, A.transactiondate, A.effectivedate
from A
where A.transactiondate >= A.effectivedate
这是我得到的结果
transactiondate|effectivedate|unitprice
19-02-19 |01-01-19 | 36
19-02-19 |28-12-18 | 30
19-02-19 |15-12-18 | 20
但我想获取这些数据
transactiondate|effectivedate|unitprice
19-02-19 |01-01-19 | 36
我使用 My SQL 服务器。请帮助我更正查询以获得我想要的数据。
最佳答案
你可以试试这个。
select A.unitprice, A.transactiondate, A.effectivedate
from A
where A.effectivedate = (select max(effectivedate) from A)
and A.effectivedate <= A.transactiondate;
关于mysql - 如何编写sql代码来获取2个日期之间的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273707/