Android - 如何在Sqlite

时间:2015-09-03 07:22:08

标签: android sqlite sum rows duplicate-data

您好我的数据库中有这样的内容 -

enter image description here

现在我需要编写一个查询,它给出了以下结果 -

enter image description here

任何帮助都会非常感激。

2 个答案:

答案 0 :(得分:1)

尝试类似:

select month, day_of_week, sum(data), count(_id)
from table
group by month, day_of_week

答案 1 :(得分:1)

您可以在Android SQLite中使用普通的SQL语句

SELECT month, day_of_week, sum(data) AS total_data, count(month)AS number_of_rows_combined 
FROM --table--
GROUP BY month, day_of_week

在Android中,您可以使用SQL作为:

Cursor c1 = db.rawQuery(
    "SELECT month, day_of_week, sum(data) AS total_data, count(_id)AS number_of_rowa_combined 
FROM --your table--
GROUP BY month, day_of_week",
    new String[] {}
);