Hi
I have this query:

`SELECT SUM(`KN`) + SUM((COALESCE(`EUR`, 0)))*7.5 FROM log WHERE `KN` IS NOT NULL and `EUR` IS NOT NULL`

And it retunrs 0

SUM(EUR)* 7.5 should be zero but SUM(KN) is 60.

I am not shure what I am doing wrong here, I want to add numbers and avoid counting NULL so where is null to set 0 that I can add values

SELECT (SUM(EUR)* 7.5) FROM log WHERE EUR IS NOT NULL
returns 0
and
SELECT SUM(KN) FROM log WHERE KN IS NOT NULL
returns 60

Thanks

The query problem is because your 'And' statement. Means if EUR is null but KN IS NOT NULL, the query still will not get the data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.