我有一张mysql表,价格如下
id element_id daily_price weekly_price since until
----------------------------------------------------------------------
1 2 400 2800 2017-01-01 2017-05-31
2 2 500 3500 2017-06-01 2017-12-31
3 2 600 4200 2018-01-01 2018-05-31
4 2 700 4900 2018-06-01 2018-12-31
我想做一个单一的查询,得到最低的每日价格和每周价格为目前的一年。如果没有为本年度设定价格,则应获得与去年相同的最低价格。
3条答案
按热度按时间yshpjwxd1#
我认为这是最简单的方法:
如果要使用联接而不是子查询,请执行以下操作:
fnx2tebb2#
您可以将join与year、min daily和min weekly子查询一起使用
oaxa6hgo3#
你可以用这个