Date Expiry Close
20-Mar-18 28-Mar-18 10143.2
20-Mar-18 26-Apr-18 10180.2
20-Mar-18 31-May-18 10201
21-Mar-18 28-Mar-18 10180.2
21-Mar-18 26-Apr-18 10218.3
21-Mar-18 31-May-18 10237.8
22-Mar-18 28-Mar-18 10127.8
22-Mar-18 26-Apr-18 10168.8
22-Mar-18 31-May-18 10193.2
23-Mar-18 28-Mar-18 10003.9
23-Mar-18 26-Apr-18 10047.6
23-Mar-18 31-May-18 10060.2
26-Mar-18 28-Mar-18 10146.2
26-Mar-18 26-Apr-18 10178.3
26-Mar-18 31-May-18 10205
27-Mar-18 28-Mar-18 10179
27-Mar-18 26-Apr-18 10215.8
27-Mar-18 31-May-18 10235.2
28-Mar-18 28-Mar-18 10120.2
28-Mar-18 26-Apr-18 10152
28-Mar-18 31-May-18 10175.3
2-Apr-18 28-Jun-18 10301.4
2-Apr-18 31-May-18 10288.2
2-Apr-18 26-Apr-18 10264
3-Apr-18 26-Apr-18 10285
3-Apr-18 31-May-18 10313.9
3-Apr-18 28-Jun-18 10327.4
4-Apr-18 26-Apr-18 10146.6
4-Apr-18 31-May-18 10175.5
4-Apr-18 28-Jun-18 10194.7
5-Apr-18 26-Apr-18 10352.2
5-Apr-18 31-May-18 10381
5-Apr-18 28-Jun-18 10398
6-Apr-18 28-Jun-18 10399.3
6-Apr-18 31-May-18 10385.1
6-Apr-18 26-Apr-18 10352.8
第一列中的每个日期都有3个与之关联的到期日期。我只想获取最接近日期(近月到期)的到期日,关闭日,到期日。
我该怎么做?谢谢。
例如,我希望结果为:
Date Expiry Close
20-Mar-18 28-Mar-18 10143.2
21-Mar-18 28-Mar-18 10180.2
22-Mar-18 28-Mar-18 10127.8
23-Mar-18 28-Mar-18 10003.9
26-Mar-18 28-Mar-18 10146.2
27-Mar-18 28-Mar-18 10179
28-Mar-18 28-Mar-18 10120.2
2-Apr-18 26-Apr-18 10264
3-Apr-18 26-Apr-18 10285
4-Apr-18 26-Apr-18 10146.6
5-Apr-18 26-Apr-18 10352.2
6-Apr-18 26-Apr-18 10352.8
最佳答案
还没有测试,我认为在MariaDB中可以奏效。请尝试以下方法:
SELECT
Date,
Expiry,
Close
FROM
table
GROUP BY
Date
ORDER BY
Expiry DESC
关于mysql - 如何在MySQL中选择近月到期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49708592/