Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gruop by??????

0 views
Skip to first unread message

Kura

unread,
Jan 31, 2000, 3:00:00 AM1/31/00
to
Hello all!
Problem:

1select :
select id_time_scale from sales where id_time_scale=31 group by
id_day_part,id_part,id_nomencl
result:
299 rows where id_time_scale=26........31

2select :
select id_time_scale from sales where id_time_scale=31
result:
90 rows where id_time_scale=31

3select :
select id_time_scale from sales group by id_day_part,id_part,id_nomencl
having id_time_scale=31
result:
90 rows where id_time_scale=31

I dont understand result of SELECT1 . Why server give me rows where
id_time_scale=26 , 27......

please help.

YuriV. Kurilin
ku...@integris.ru


Ivan Santhumayor

unread,
Jan 31, 2000, 3:00:00 AM1/31/00
to
Unfortunately, this is a designed feature of T-SQL whereby the GROUP BY
includes even rows cutoff by the WHERE Clause. To get the results you expect,
put the same WHERE conditions in the HAVING clause as well.
Oracle and other ANSI SQL flavours work the way you expect and not the way
Sybase works.

Note: These are my own views and not that of Goldman Sachs.

Stephen Prowse

unread,
Jan 31, 2000, 3:00:00 AM1/31/00
to
Kura,
The group by is used when you are calculating an aggregate in the query eg;

select id_time_scale, count(id_time_scale)
from sales
group by id_time_scale

will give you the number of rows for each instance of id_time_scale.

Using with out an aggregate is I believe a cartesian product and every row
is selected.

From the code fragment below you don't need the group by as the simple
select is more efficient and does what you want

--
Steve Prowse
All statements are mine and mine alone until I'm told otherwise.
The good thing about procrastination?
You've always got something planned for tomorrow.

:
:
:


0 new messages