【问题标题】:Get the difference of Values between two records in sqlite获取sqlite中两条记录之间的值差异
【发布时间】:2013-03-29 07:23:13
【问题描述】:

我有一个包含以下数据的 sqlite 表,

 _Id       Mode         Reading
  1       Water           100
  2       Water           300
  5       Water           496
  6       Water           600     

现在我想要记录之间值的差异。例如, b/w(列读数)100 和 300 的差异是“200”,300 和 496 是“196”,496 和 600 是“104”。

我希望查询结果为,

 Reading
  200
  196
  104

如何在 sqlite 中完成这项工作? 任何人都可以帮忙。我的sqlite很差。

任何帮助将不胜感激!提前致谢!!

【问题讨论】:

  • Mode 列是否与此问题相关?

标签: android sqlite records


【解决方案1】:

使用游标从数据库中检索值并执行以下操作:

   cursor.moveToNext();
   int prevVal = cursor.getInt(2);
   while(cursor.moveToNext())
   {
      int curVal= cursor.getInt(2);
      int reading = curVal-prevVal;
      prevVal=curVal;
   }

您可以将reading 声明为一个数组并在之后显示它。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-09-29
  • 2021-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-28
  • 1970-01-01
  • 2021-03-18
相关资源
最近更新 更多