我如何获得最低价值成功?

时间:2017-06-26 01:58:20

标签: android android-sqlite

我的sql表是这样的:

enter image description here

我想得到最大值和最小值,我尝试这样的方法:

//get the highest value
public String getMax(String column_name) {// use the data type of the column
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.query(TABLE_CONTACTS, new String[]{"MAX(" +column_name + ") AS MAX"}, null, null, null, null, null);

    cursor.moveToFirst(); // to move the cursor to first record
    int index = cursor.getColumnIndex("MAX");
    String data = cursor.getString(index);// use the data type of the column or use String itself you can parse it

    db.close();

    System.out.println("maxData:"+data);
    return data;
}

//get the minimum value
public String getMin(String column_name) {// use the data type of the column
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.query(TABLE_CONTACTS, new String[]{"MIN(" +column_name + ") AS MIN"}, null, null, null, null, null);

    cursor.moveToFirst(); // to move the cursor to first record
    int index = cursor.getColumnIndex("MIN");
    String data = cursor.getString(index);// use the data type of the column or use String itself you can parse it

    db.close();

    System.out.println("minData:"+data);
    return data;
}

我在六个setText上调用方法和TextView

结果显示最大值很好,问题是最小值,某种最小值为空。

private void setMinMaxValue(){
    minBeMorning.setText(db.getMin("bMorning"));
    minAfMorning.setText(db.getMin("aMorning"));
    minBeNoon.setText(db.getMin("bNoon"));
    minAfNoon.setText(db.getMin("aNoon"));
    minBeNight.setText(db.getMin("bNight"));
    minAfNight.setText(db.getMin("aNight"));

    maxBeMorning.setText(db.getMax("bMorning"));
    maxAfMorning.setText(db.getMax("aMorning"));
    maxBeNoon.setText(db.getMax("bNoon"));
    maxAfNoon.setText(db.getMax("aNoon"));
    maxBeNight.setText(db.getMax("bNight"));
    maxAfNight.setText(db.getMax("aNight"));
}

这是我的日志猫:

06-26 09:43:45.115 22517-22517/? I/System.out: minData:71
06-26 09:43:45.116 22517-22517/? I/System.out: minData:112
06-26 09:43:45.118 22517-22517/? I/System.out: minData:
06-26 09:43:45.119 22517-22517/? I/System.out: minData:
06-26 09:43:45.121 22517-22517/? I/System.out: minData:
06-26 09:43:45.122 22517-22517/? I/System.out: minData:
06-26 09:43:45.125 22517-22517/? I/System.out: maxData:98
06-26 09:43:45.126 22517-22517/? I/System.out: maxData:99
06-26 09:43:45.128 22517-22517/? I/System.out: maxData:96
06-26 09:43:45.129 22517-22517/? I/System.out: maxData:142
06-26 09:43:45.131 22517-22517/? I/System.out: maxData:98
06-26 09:43:45.132 22517-22517/? I/System.out: maxData:151

我认为bNoon aNoon bNight aNight的最小值应为93 122 95 132,但现在它们为空。

有人可以告诉我我想念它的步骤,提前谢谢。

1 个答案:

答案 0 :(得分:1)

也许您已将actiononChangebNoonaNoon定义为bNight 将该值更改为aNight并尝试使用您的代码。