Subject | SUM and null values |
---|---|
Author | kokok_kokok |
Post date | 2011-11-25T11:07:07Z |
How can I get NULL from SUM when a value is NULL?
I know that aggregate functions only use non null values.
My problem is different. I want to sum a list of values, but if one or more is null, then I would need to get NULL.
For example, table person:
Name, Weight
-----,----
John, 50
Paul, 100
Mary, NULL
If I do "SELECT SUM(Weight) FROM Persons", I get 150.
I would like to get NULL since we do not know the weight of Mary, and then it is not possible to get the total weight.
How can I do it?
Thank you
I know that aggregate functions only use non null values.
My problem is different. I want to sum a list of values, but if one or more is null, then I would need to get NULL.
For example, table person:
Name, Weight
-----,----
John, 50
Paul, 100
Mary, NULL
If I do "SELECT SUM(Weight) FROM Persons", I get 150.
I would like to get NULL since we do not know the weight of Mary, and then it is not possible to get the total weight.
How can I do it?
Thank you