[thelist] SQL - Group by peculiarity in Sybase
VOLKAN ÖZÇELİK
volkan.ozcelik at gmail.com
Thu Apr 14 09:44:19 CDT 2005
Hi Database-lover evolters!
I have a really simple query:
SELECT taktar,taktut, "sum(taktut)" as toplam FROM p_taksit
WHERE (necessary filters)
which returns a single row.:
Apr 14 2005 12:00 AM - 95.38 - "sum(taktut)"
When I alter the query to:
SELECT taktar,taktut, sum(taktut) as toplam FROM p_taksit
WHERE (necessary filters)
-note that the quotes around sum(taktut) are removed-
According to my logic I should get.
Apr 14 2005 12:00 AM - 95.38 - 95.38
i.e the aggregate of the first query.
However I get around 32000+ rows (the entire table), the returned
result is not filtered by (necessary filters) as well. It disregards
the date range I give etc etc.
It simply returns the entire table.
I hear you saying "hey why don't you group by taktut?"
Well, definetely it will solve the problem. I just wonder why the db
goes mad when I do not aggregate it. Just a technical curiosity.
According to ANSI SQL standards it should first apply filters and then
aggregate. I guess it acts the other way around.
Btw we use Sybase as per the DB. version 12.0.0.4 / 64 Bit.
Is it the weirdness of sybase, or am I missing something apparent?
Thanks very much in advance.
Volkan.
More information about the thelist
mailing list