Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 GROUP BY clause

Author  Topic 

Antonio
Posting Yak Master

168 Posts

Posted - 2007-02-02 : 12:08:36
Hi there,

Why doesn't the following work?! What am I missing here?


select btg_opty_id,
result_type_number,
'c' as a
from
RESULT_FACT_ETL_OUTPUT
group by btg_opty_id,
result_type_number,
'c'


_________________________________________________________________________________________________________________________
Inability is a disaster; patience is bravery; abstinence is a treasure, self-restraint is a shield; and the best companion is submission to Divine Will.

PurpleSun
Yak Posting Veteran

50 Posts

Posted - 2007-02-02 : 12:13:50
Why do you need group by? Use order by instead.

quote:
Originally posted by Antonio

Hi there,

Why doesn't the following work?! What am I missing here?


select btg_opty_id,
result_type_number,
'c' as a
from
RESULT_FACT_ETL_OUTPUT
group by btg_opty_id,
result_type_number,
'c'


_________________________________________________________________________________________________________________________
Inability is a disaster; patience is bravery; abstinence is a treasure, self-restraint is a shield; and the best companion is submission to Divine Will.

Go to Top of Page

sshelper
Posting Yak Master

216 Posts

Posted - 2007-02-02 : 12:23:50
Remove the 'c' in the GROUP BY because this is just a literal and you don't need it there:

select btg_opty_id,
result_type_number,
'c' as a
from
RESULT_FACT_ETL_OUTPUT
group by btg_opty_id,
result_type_number


SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-02 : 14:27:08
select distinct btg_opty_id,
result_type_number,
'c' as a
from
RESULT_FACT_ETL_OUTPUT


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Antonio
Posting Yak Master

168 Posts

Posted - 2007-02-06 : 04:10:07
quote:
Originally posted by sshelper

Remove the 'c' in the GROUP BY because this is just a literal and you don't need it there:

select btg_opty_id,
result_type_number,
'c' as a
from
RESULT_FACT_ETL_OUTPUT
group by btg_opty_id,
result_type_number


SQL Server Helper
http://www.sql-server-helper.com



Thanks for your help. That worked.

_________________________________________________________________________________________________________________________
Inability is a disaster; patience is bravery; abstinence is a treasure, self-restraint is a shield; and the best companion is submission to Divine Will.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-06 : 04:32:21
Speed wise, how does that approach (group by) compare with DISTINCT?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Antonio
Posting Yak Master

168 Posts

Posted - 2007-02-07 : 12:22:53
quote:
Originally posted by Peso

Speed wise, how does that approach (group by) compare with DISTINCT?


Peter Larsson
Helsingborg, Sweden



I've not really tested the speed of the different approaches but there was a time when using DISTINSCT was considered slower that using a GROUP BY clause.


_________________________________________________________________________________________________________________________
Inability is a disaster; patience is bravery; abstinence is a treasure, self-restraint is a shield; and the best companion is submission to Divine Will.
Go to Top of Page
   

- Advertisement -