Practice mode DBMS and SQL

Table Stock(item, qty) has rows (‘a’,8), (‘b’,12), (‘c’,20), (‘d’,15). UPDATE Stock SET qty = qty – 5 WHERE qty > 10; SELECT SUM(qty) FROM Stock; What is the result?

Correct answer D. 40

Explanation

The UPDATE changes only rows whose qty exceeds 10: b, c and d each fall by 5 to 7, 15 and 10. Row a (8) is untouched. The new total is 8 + 7 + 15 + 10 = 40. The answer 35 assumes every row was reduced, which is what happens if the WHERE clause is left out; the original total before the update was 55.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.