Direct subtraction in a view query?

Asked

Viewed 301 times

0

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

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

2 answers

6

Using Alias in SQL.

SELECT (NFValIcmsSubs - NFValFCP) as NFValIcmsSubs FROM TABELA

3

Specifically for your case the answer of friend Everson is the one that answers your question.

But 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 calculus operations, Mysql also has precepts between operators. Thus, the multiplication and division operators are considered before the addition and subtraction operators. If two operators have the same priority, the expression is read from left to right. Use parentheses to force prioritization and to improve readability of expression.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.