鉴于下面的示例数据,我如何才能每分钟只获取一行time
?
然后我需要做出这样的条件:
SELECT IF (`Flag` IS NOT NULL,
[fetch flag row],
[otherwise fetch one row from that minute]);
样本数据
ID Rate Flag time
1 68.65 null 2012-04-18 10.00.01
2 68.63 null 2012-04-18 10.00.11
3 68.68 null 2012-04-18 10.00.21
4 68.70 null 2012-04-18 10.00.31
5 68.71 null 2012-04-18 10.00.41
6 68.60 null 2012-04-18 10.00.51
7 68.64 null 2012-04-18 10.01.01
8 68.75 null 2012-04-18 10.01.11
9 68.72 1 2012-04-18 10.01.21
10 68.63 null 2012-04-18 10.01.31
11 68.62 null 2012-04-18 10.01.41
12 68.60 null 2012-04-18 10.01.51
Expected Output
1 68.65 null 2012-04-18 10.00.01
9 68.72 1 2012-04-18 10.01.21
这是我到目前为止所得到的:
SELECT FLAG as signal, DATE_FORMAT(TIME, '%Y-%m-%d %H:%i') as time, RATE as rate
FROM RATES WHERE (FLAG!='' || (DATE_FORMAT(TIME, '%s')>50 ))
GROUP BY time
ORDER BY time DESC,FLAG DESC;