Direct query subtraction of a view?

0

I have view dbo.ViewExportItensNotasFiscais , I have the NFValIcmsSubs field, where it is necessary to subtract the value of the NFValFCP field and keep the column name as NFValIcmsSubs

How could I do a direct subtraction of Query from a View ?

    
asked by anonymous 31.05.2017 / 16:15

2 answers

6

Using Alias in SQL.

SELECT (NFValIcmsSubs - NFValFCP) as NFValIcmsSubs FROM TABELA
    
31.05.2017 / 16:18
3

Specifically for your case, Everson's answer is the one that answers your question.

However, the MySQL client can also perform some operations with some additional level of complexity.

Examples:

SELECT (NFValIcmsSubs - NFValFCP)*2 as NFValIcmsSubs FROM TABELA

SELECT (NFValIcmsSubs - NFValFCP)*(FValIcmsSubs + NFValFCP) as NFValIcmsSubs FROM TABELA

As with basic arithmetic calculations, MySQL also has precedence between operators. Thus, multiplication and division operators are considered before addition and subtraction operators. If two operators have the same priority, the expression is read from left to right. Use the parentheses to force prioritization and improve the legibility of the expression.

    
31.05.2017 / 17:01