On Sep 8, 2005, at 5:20 PM, Ted Unangst wrote:

Robert Simpson wrote:
Lets take the October sales further. Lets say if there were any sales in October, that you had to subtract $100 from the total sales for October to account for ... lets say "shipping costs".
SELECT SUM(amt) - 100 from sales where month = 'october'
If there were no sales, under your query plan, I'd still have been in the hole $100. This is vastly oversimplified in order to show that "0" does not always answer the question and can cascade into an even worse scenario.

I would think "SELECT SUM(amt)" means "How much did I sell?" or "What was my income?", and a better query here would be "SELECT SUM(amt) - SUM(costs)". Just because there were no sales doesn't mean that the profit (or loss) is indeterminate. If your boss asked you "How much did you make in October?" the answer is not "I can't tell."


oh yes, it is the correct answer. "I can't tell because I don't have the data." Therein lies the problem... if we contrive concrete examples, we can go both ways -- the way of NULL or the way of 0. The fact is, NULL is the absence of data. Hence, I can't tell is a valid answer.


--
Puneet Kishor

Reply via email to