SQLite的如何总结在`GridView`列的值 [英] SQLite how to sum the values of column in `GridView`

查看:120
本文介绍了SQLite的如何总结在`GridView`列的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经环顾四周,发现了一些类似的情况,但没有哪里有需要的条目特异性总结。所以我在这里。

我有一个方法 filterPayments 返回我的赔率表基于特定组ID ,然后在我的 GridView控件显示。从那里,我想总结在赔率表的5列2的值,特别是我的兴趣由于列。我不知道如何在一个查询做到这一点,更不用说只对特定的列做。

我如何添加所有项的值在一个特定的列。

是否有可能做到这一点的一个SQLite查询? 如果这样我怎么使用 filterPayments 的返回值,只有在特定的列进行求和? 如果它不是,然后我该怎么做呢?

下面是我的code片段。

filterPayments

 光标filterPayments(字符串付款){
    SQLiteDatabase分贝= this.getWritableDatabase();
    的String [] =列新的String [] {_ ID,colGroupID,colPayBal,colInterest,colDue,colDateDue,colPaid};
    光标C = db.query(viewPmnts,列colGroupID +=?,新的String [] {}付款,NULL,NULL,NULL);
    返回℃;
}

GridView控件

 公共无效Paygrid(){    dbHelper =新DatabaseHelper(本);
    字符串付款=将String.valueOf(txt.getText());
    光标= dbHelper.filterPayments(支付);
    startManagingCursor(一);    的String [] =由新的String [] {DatabaseHelper.colPayBal,DatabaseHelper.colInterest,DatabaseHelper.colDue,DatabaseHelper.colDateDue,DatabaseHelper.colPaid};
    INT []为= INT新[] {R.id.Amount,R.id.Interest,R.id.Due,R.id.DateDue,R.id.Paid};    SimpleCursorAdapter SAA =新SimpleCursorAdapter(这一点,R.layout.paygrid,一个从,到);
    intgrid.setAdapter(SAA);
}


解决方案

我建议甩开列中的所有数据,然后总结他们的Java或Android。这将是最简单的方法。

有没有核心的SQLite函数做的。
https://www.sqlite.org/lang_corefunc.html

但是,您可以创建自定义的源码功能。下面看。
如何创建SQLite中自定义函数

I've had a look around and found a few similar cases but none where there is a need for specificity in the entries to sum. So here I am.

I have a method filterPayments that returns all entries in my PayTable based on a specific GroupID and is then displayed in my GridView. From there I want to sum the values of 2 of the 5 columns in PayTable, specifically my Interest and Due columns. I'm not sure how to do this in a query, let alone do it only for specific columns.

Question

How do I add the values of all entries in a specific column.

Is it possible to do this in a SQLite query? If so how do I use the returned value of filterPayments and perform the summation only on specific columns? If it isn't then how can I do this?

Below are my code snippets.

filterPayments

Cursor filterPayments(String Payment) {
    SQLiteDatabase db = this.getWritableDatabase();
    String[] columns = new String[]{"_id", colGroupID, colPayBal, colInterest, colDue, colDateDue, colPaid};
    Cursor c = db.query(viewPmnts, columns, colGroupID + "=?", new String[]{Payment}, null, null, null);
    return c;
}

GridView

public void Paygrid() {

    dbHelper = new DatabaseHelper(this);
    String Payment = String.valueOf(txt.getText());
    Cursor a = dbHelper.filterPayments(Payment);
    startManagingCursor(a);

    String[] from = new String[]{DatabaseHelper.colPayBal, DatabaseHelper.colInterest, DatabaseHelper.colDue, DatabaseHelper.colDateDue, DatabaseHelper.colPaid};
    int[] to = new int[]{R.id.Amount, R.id.Interest, R.id.Due, R.id.DateDue, R.id.Paid};

    SimpleCursorAdapter saa = new SimpleCursorAdapter(this, R.layout.paygrid, a, from, to);
    intgrid.setAdapter(saa);
}

解决方案

I suggest pulling all the data from column and then sum them in Java or android. That would be the simplest way.

There are no core sqlite functions that does it. https://www.sqlite.org/lang_corefunc.html

You can however create custom sqlite functions. Look below. How to create custom functions in SQLite

这篇关于SQLite的如何总结在`GridView`列的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆