Column Summing Problem in SQLite

Hello, I’m working on an app and have to sum up the

one of the columns in the database.

Surely I make a mistake, but I can not handle myself, so please for your help.

In the console returns nil, and there are values (digits) in the database column.

Please give advice on how to sum the column values in the database.

Excuse me for my bad English.

1. local sumata 2. local obCena\_sum 3. 4. local path = system.pathForFile( "mydatabase.db", system.DocumentsDirectory ) 5. 6. local db = sqlite3.open( path ) 7. 8. local sumata = [[SELECT SUM ( obCena) FROM accounts AS obCena\_sum]] 9. 10. db:exec( sumata ) 11. 12. print( obCena\_sum )

[lua]

local path = system.pathForFile( “mydatabase.db”, system.DocumentsDirectory )

local db = sqlite3.open( path )

local query = [[SELECT SUM ( obCena) FROM accounts AS obCena_sum]]

local obCena_sum = 0

for row in db:nrows(query) do

  obCena_sum = row.obCena_sum

end

print( obCena_sum )

[/lua]

Hi nick sherman,

Thanks for the suggestion, I change the code, but the result is same.

In the console print : nil

EDIT: your query was incorrect.

[lua]

  1. local query = [[SELECT SUM (obCena) AS obCena_sum FROM accounts]]

[/lua]

Thanks nick sherman,

I edit the query and all work perfectly!

Here is the code for others members to consul if necesary.

Thanks !

 local path = system.pathForFile( "mydatabase.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) local query = [[SELECT SUM ( obCena) AS obCena\_sum FROM accounts]] local obCena\_sum = 0 for row in db:nrows(query) do obCena\_sum = row.obCena\_sum end print( obCena\_sum )

[lua]

local path = system.pathForFile( “mydatabase.db”, system.DocumentsDirectory )

local db = sqlite3.open( path )

local query = [[SELECT SUM ( obCena) FROM accounts AS obCena_sum]]

local obCena_sum = 0

for row in db:nrows(query) do

  obCena_sum = row.obCena_sum

end

print( obCena_sum )

[/lua]

Hi nick sherman,

Thanks for the suggestion, I change the code, but the result is same.

In the console print : nil

EDIT: your query was incorrect.

[lua]

  1. local query = [[SELECT SUM (obCena) AS obCena_sum FROM accounts]]

[/lua]

Thanks nick sherman,

I edit the query and all work perfectly!

Here is the code for others members to consul if necesary.

Thanks !

 local path = system.pathForFile( "mydatabase.db", system.DocumentsDirectory ) local db = sqlite3.open( path ) local query = [[SELECT SUM ( obCena) AS obCena\_sum FROM accounts]] local obCena\_sum = 0 for row in db:nrows(query) do obCena\_sum = row.obCena\_sum end print( obCena\_sum )