Alasql: Query result is wrong

Created on 5 Dec 2019  路  8Comments  路  Source: agershun/alasql

My query didn't give me the expected result: see the following fiddle:
http://jsfiddle.net/c4w1b8a6/1/

Is there any fix for it? thank you very much

Damien

! Bug Code provided to reproduced Help wanted SQL compliance

All 8 comments

Hi Damien.

Could you explain a little more what you are trying to achieve with the query?
Maybe it can be written in a simpler way.

Hi,

I really need this query in this format and I cannot write it in another format. I have investigated and it seems that as I am using 3 times sum(population) somewhere a variable is not reinitialised properly. If you replace sum per avg you will get the same problem unfortunately.
Could we get a fix for that?

Damien

The first step is to try to shrink the issue to its most simple version.

Anyone who can make the SQL more simple but keeping the problem? It would be much appreciated.

Hi mathias
I tried to make the code more readable on this jsfiddle. I hope that could help.
http://jsfiddle.net/nxvst87c/1/

Best regards and happy new year

Hmm weird.

If you move the last to sums as the first rows then the result is the same, must be some really strange issue internally to behave like this.

What's also interesting is that if you change the column named "val4" to val3" (meaning there are 2 columns with the name "val3") the larger incorrect value of 20481179 is preferred and the other column is dropped from the output.

For fun I ran the above as a subquery with both columns aliased as "val3", and received the same result.

That said, I don't believe you are supposed to be able to have 2 aliases with the same name inside a subquery (not in T-SQL at least).

I'll see if I can find an existing issue tracking this and if it doesn't exist I can create a new one.

This is also interesting and could maybe help the ones with more internal insights.

If one changes the line

sum(population) as val4

to

sum(population+1-1) as val4

val3 and val4 will be equal

sum(population+0) as val4

also works :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SWard1992 picture SWard1992  路  3Comments

cscan picture cscan  路  4Comments

carloszimm picture carloszimm  路  3Comments

daffodilistic picture daffodilistic  路  3Comments

karubimania picture karubimania  路  6Comments