Skip to content
Advertisement

I have been looking for solution to get sum of multiple columns(for a single row) in Mysql to get total of every hour for electricity invoice?

I wrote below query to get sum but it is showing(something progressing) total as null for couple of records. It is showing 1064 error at line 4 when I include all records like below.

Advertisement

Answer

it is showing total as null for couple of records

Probably, at least one of the columns has a null value for those records. In MySQL (and most other RDBMS), 1 + null yields null. You can work around this with coalesce():

It is showing 1064 error at line 4

column_alias = <expression> is not valid MySQL syntax (this is a SQL Server syntax). You should put the column alias after the expression, optionaly preceeded by keyworkd as, like:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement