Re: Semantics of SUM

On 10 Nov 2009, at 18:25, Andy Seaborne wrote:
> On 10/11/2009 17:57, Steve Harris wrote:
>>> > Consensus that SUM/AVG should use same semantics as +
>>>
>>> Clarification: errors not in a group means that what would be
>>>
>>> 1 + error + 2 => 3
>>>
>>> which is not the same as +
>>
>> Yep, which I think is why they are in the group, and why COALESCE is
>> important.
>
> I don't see that COALESCE helps because there isn't an intermediate  
> variable representing the sum so far.

I think the idea was something like:

SELECT SUM(COALESCE(xsd:double(?x), 0))
WHERE {
   <x> <value> ?x .
}

That parallels what you do in SQL:

 > SELECT * FROM C;
+------+
| val  |
+------+
| 1    |
| 2    |
| 5    |
| 23   |
| NULL |
+------+

 > SELECT SUM(COALESCE(val, 100)) FROM C;
+-------------------------+
| SUM(COALESCE(val, 100)) |
+-------------------------+
|                     131 |
+-------------------------+

- Steve

-- 
Steve Harris, CTO, Garlik Limited
2 Sheen Road, Richmond, TW9 1AE, UK
+44(0)20 8973 2465  http://www.garlik.com/
Registered in England and Wales 535 7233 VAT # 849 0517 11
Registered office: Thames House, Portsmouth Road, Esher, Surrey, KT10  
9AD

Received on Tuesday, 10 November 2009 18:48:09 UTC