I have the following database table and I want to extract the Monthly profit (from the profit column) information with the optimal code.
Does anyone have a solution ??
I store date from Calendar.getTimeInMilliseconds() in SQLite DB. I need to mark first rows by every month in SELECT statement, so I need convert time in milliseconds into any date format using SQLite
stackoverflow.com
Do this to your date column and in a second query use it to group by month
I store date from Calendar.getTimeInMilliseconds() in SQLite DB. I need to mark first rows by every month in SELECT statement, so I need convert time in milliseconds into any date format using SQLite
stackoverflow.com
Do this to your date column and in a second query use it to group by month
many thanks
after many search and test i write this query
and its work fine
B4X:
Dim RS As ResultSet=Sql1.ExecQuery($"SELECT strftime('%Y', date / 1000, 'unixepoch') as year,
strftime('%m', date / 1000, 'unixepoch') as month,
SUM( profit ) AS sum FROM tbl2 GROUP BY month;"$)
Do While RS.NextRow
Log(RS.GetString("year"))
Log(RS.GetString("month"))
Log(RS.GetString("sum"))
Log("====================")
Loop
RS.Close
*** if you used UnixTime you should use this
strftime('%Y', date)
many thanks
after many search and test i write this query
and its work fine
B4X:
Dim RS As ResultSet=Sql1.ExecQuery($"SELECT strftime('%Y', date / 1000, 'unixepoch') as year,
strftime('%m', date / 1000, 'unixepoch') as month,
SUM( profit ) AS sum FROM tbl2 GROUP BY month;"$)
Do While RS.NextRow
Log(RS.GetString("year"))
Log(RS.GetString("month"))
Log(RS.GetString("sum"))
Log("====================")
Loop
RS.Close
*** if you used UnixTime you should use this
strftime('%Y', date)