Android - How to combine rows based on duplicate data in Sqlite

464 Views Asked by At

Hi I have something like this in my database -

enter image description here

Now I need to write a query that gives me the following result -

enter image description here

Any help would be really appreciated.

2

There are 2 best solutions below

0
Jaroslav Klech On BEST ANSWER

You can use normal SQL statements in Android SQLite

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

in Android you can use SQL as:

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[] {}
);
0
Flo On

Try something like:

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