Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite get sum of data by weekly

Tags:

android

sqlite

I have database table that stores data daily

My table current_list contains:

  • id (autoincrement)
  • day (DATE NOT NULL DEFAULT (date('now')))
  • app_data (INTGER)
  • mobile_data (INTEGER)

From this table I am able to get data weekly by executing the below query

SELECT id AS id, strftime('%W', day) AS week, app_data, mobile_data
FROM current_list order by week;

which gives me

| id | week | app_data | mobile_data
| 01 | 00   | 100      |  200
| 02 | 00   | 200      |  300
| 03 | 00   | 400      |  670
| 04 | 01   | 700      |  340
| 05 | 01   | 600      |  560 
| 06 | 01   | 560      |  230

Now, I need sum of app_data, mobile_data weeklywise. It should be like

| week | Sum(app_data) | Sum(mobile_data)
| 00   | 700           |  1170
| 01   | 1860          |  1300

Can anyone help in this?

like image 960
ronie Avatar asked Oct 09 '22 02:10

ronie


1 Answers

SELECT strftime('%W', day) AS week, sum(app_data), sum(mobile_data) FROM current_list order by week GROUP BY week

like image 178
sebastianf182 Avatar answered Oct 17 '22 10:10

sebastianf182