In a Virtual layer I'm trying to sum the values (real) on a table (
'PESQUISA') but it returns
NULL. What am I doing wrong?
This is the code I'm using:
select sum("renda_mensal") as sum from PESQUISA
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Let's assume there a point layer called
'random_points_test' with it's attribute table, see image below
When I apply the following SQL query for a 'Virtual Layer' through
Layer > Add Layer > Add/Edit Virtual Layer...
SELECT SUM(p."Value_1") AS sum_1, SUM(p."Value_2") AS sum_2, SUM(p."Value_3") AS sum_3 FROM "random_points_test" AS p
However, appearing of
NULL in the attribute table will not (shall not) affect the calculation, see images below.
Despite even a string data type, you can calculate the sum of values (real, integer, string) using the Virtual Layer (It seems to be really smart). So, I would claim that there is either something wrong with your data import or with values (the histogram of values may help here).
As a workaround I may refer you to one of my answers, see this.