8
I participated in the IFNMG competition, a test prepared by the CEFET Foundation. I solved the following question and marked the letter C, but the feedback says that the correct is the letter A.
Question 31
Consider that the Notafiscalitem table is stored in a
relational database manager system (DBMS), containing the following data.
Table: Notafiscalitem
Then note the SQL command shown below.
Figure: SQL command
The result produced by executing the SQL command, when considering the data presented in the Notafiscalitem table, is
a) 28,00 7,00 48,00
b) 28,00 NULL NULL
c) 48,00 7,00 48,00
d) 48,00 0,00 55,00
e) NULL NULL NULL
Does the statement "sum(qtd_item*vlr_unitario - vlr_desconto)" not add the first line for "null" in the "vlr_desconto" column? But that doesn’t depend on the DBMS you’re using?
Could you transcribe the question in your question? Leaving it as an image impairs its publication, because many users cannot view the images and the search system does not index its content.
– Woss
Okay, whatever is in text I’ll leave in text, but the table and the instruction is figure. Thank you
– Denis Caixeta
Yes, the
NULL
invalidates the rest of the calculation.(2*10 - NULL)
will always returnNULL
. In order for it to be the option A it would have to have that way (there are other):sum(qtd_item*vlr_unitario - ISNULL(vlr_desconto, 0)
.– João Martins
@Joãomartins actually in Mysql does not work that way...
– Sorack
@Sorack as he knew it was Mysql and not SQL Server?
– João Martins
The DBMS has not been specified and it is precisely at this point that I think the question is can be annulled.
– Denis Caixeta
@Joãomartins do not know which BDS, I gave just one example... in fact I think the issue deals with the ANSI standard
– Sorack
@Sorack Yes, but even so would have to have specified in the statement that it is the ANSI standard and not a specific DBMS, since depending on the DBMS the behavior may be different.
– Denis Caixeta
@Deniscaixeta understood. And yet it seems that it is a trick since it has different behaviors even
– Sorack
Relational banks have different behaviors regarding this null question. Firebird would return null in all three calculations, while mysql would ignore nulls.
– Braytiner