【问题标题】:How to retrieve the first record in sqllite where a data has changed如何在sqlite中检索数据已更改的第一条记录
【发布时间】:2018-07-31 18:12:48
【问题描述】:

我有下表

ID Integer, date Text, battery_level Text , charging_sataus Text. 

现在假设我有以下数据:

1, 7/31/2018 ,50% , discharging
2, 7/31/2018 ,40% , discharging
3, 7/31/2018 ,30% , discharging
4, 7/31/2018 ,30% , charging
5, 7/31/2018 ,40% , charging
6, 7/31/2018 ,50% , charging

现在我想检索数据,比如说放电后第一次充电和放电前最后一次充电

请帮忙

谢谢 崇德

【问题讨论】:

    标签: android sql sqlite


    【解决方案1】:

    放电后第一次充电:

    select t.*
    from t
    where t.charging_status = 'charging' and
          t.id > (select min(t2.id) from t t2 where t2.charging_status = 'discharge')
    order by t2.id asc
    limit 1;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多