I have this table (made from a SQL query):
Row 1 Row 2
2 1
3 NULL
And I want to minus the 2 columns, so I just select like this:
Select Row1 - Row2
From table
But then I get this result:
1
NULL
instead of:
1
3
How can I make it possible to get the last result?
The Minus Operator in SQL is used with two SELECT statements. The MINUS operator is used to subtract the result set obtained by first SELECT query from the result set obtained by second SELECT query.
Minus Query TIP: The MINUS operator is not supported in all SQL databases. It can used in databases such as Oracle. For databases such as SQL Server, PostgreSQL, and SQLite, use the EXCEPT operator to perform this type of query.
SQL has the is [not] null predicate to test if a particular value is null . With is [not] distinct from SQL also provides a comparison operator that treats two null values as the same. Note that you have to use the negated form with not to arrive at similar logic to the equals ( = ) operator.
MySQL and PostgreSQL cannot sum up NULL values with the + value. The sum value will be NULL . If you want to do additions in the database: use SUM if it's an option to sum up a column of a result set instead of expressions ( SUM ignores NULL values)
Please try:
SELECT ISNULL([Row 1], 0) - ISNULL([Row 2], 0) from YourTable
For more Information visit ISNULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With