我有一个显示日期时间和电池电量的数据集;
| 2013-05-14 09:40:30 | 29 |
| 2013-05-14 09:41:31 | 24 |
| 2013-05-14 09:42:31 | 10 |
| 2013-05-14 09:43:33 | 5 |
| 2013-05-14 09:44:34 | 50 | -> battery charge started
| 2013-05-14 09:50:35 | 70 |
| 2013-05-14 09:51:36 | 100 | -> battery full
| 2013-05-14 09:52:37 | 90 |
| 2013-05-14 09:53:37 | 75 |
| 2013-05-14 09:54:39 | 32 |
| 2013-05-14 09:55:39 | 19 |
| 2013-05-14 09:56:40 | 2 |
| 2013-05-14 09:54:39 | 42 | -> battery charge started
| 2013-05-14 09:55:39 | 89 |
| 2013-05-14 09:56:40 | 100 | -> battery full
| 2013-05-14 09:57:39 | 100 |
| 2013-05-14 09:58:39 | 99 |
我想计算电池充满电的次数..我不能简单计算100%的电量(因为你看到底部)我有多行有时显示100 %(最多几天,具体取决于设备的使用情况)。 有人知道使用mysql计算峰值的方法吗?所以在上面的例子中,结果应该是2 ..在示例中,datetime有点浓缩..实际上是跨越一周。
答案 0 :(得分:1)
这应该可以解决问题:
SELECT * FROM (
SELECT
pit,
IF(@oldcharge<>100 OR chargeperc<>100,@oldcharge:=chargeperc,101) AS charge
FROM
(SELECT @oldcharge:=0) AS init,
charging
ORDER BY pit
) AS baseview
WHERE charge=100;
说明: