mysql使用同一组的MIN值更新组的MAX值,多行

时间:2018-08-01 01:08:18

标签: mysql sql

我想使用同一组的MIN(id)值来更新组(open)的MAX(id)的exchange, base_currency, quote_currency, DATE(created_at)值。

id last open exchange base_curr quote_curr created_at

6  1.11 0.00 ex1      usd       yen        2018-07-29 03:00:00 --> update open with 1.09 (MIN(last) of group)          
5  1.09 0.00 ex1      usd       yen        2018-07-29 02:00:00
4  1.14 0.00 ex1      usd       yen        2018-07-29 01:00:00

3  0.49 0.00 ex2      yen       won        2018-07-29 03:00:00 --> update open with 0.49 (MIN(last) of group)
2  0.51 0.00 ex2      yen       won        2018-07-29 02:00:00
1  0.50 0.00 ex2      yen       won        2018-07-29 01:00:00

我知道如何获取组的所有MIN(id),但不确定如何使用这些值更新组的MAX(id)的open值。

MAX(id)或MAX(created_at)将为我提供组的最新行。

SELECT MIN(id) as min_id, last
FROM tickers 
WHERE DATE(created_at) = '2018-07-29' 
GROUP BY exchange, base_currency, quote_currency, DATE(created_at)

1 个答案:

答案 0 :(得分:0)

我想你想要

== 1