Given PAYMENT table
(
    ID   INTEGER NOT NULL,
    PAY  INTEGER
);
that contains data:
ID	PAY
1	100
2	200
3	300
4	NULL
5	400
What will the followng query return:
SELECT
    AVG(PAY)-SUM(PAY)/COUNT(*) AS A
FROM PAYMENT
Explanation
AVG(PAY) will evaluate to 250. AVG() function ignores NULL values, so it will calculate average over all records containing not NULL values.
SUM(PAY) will evaluate to 1000 for the same reason.
COUNT(*) will evaluate to 5 as there are 5 records in the table. It doesn't make any distinctions for NULL values whatsoever.
So, the query will return 250 -1000/5=50.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести