I know you can't use an alias in a group by, but is there any way to group b
y
a constant in the select list? See the following northwind sample of my
problem.
use NORTHWIND
select city, 'blah'
from customers
group BY ciy, 'blah'
having count(*) > 5You don't need to put the constant in the GROUP BY list:
select city, 'blah'
from customers
group BY city
having count(*) > 5
If that doesn't answer your question then please show us exactly what
result you want from this query.
David Portas
SQL Server MVP
--|||Why do you need to group by that? It doesn't make any sense. Just use:
select city, 'blah'
from customers
group BY city
having count(*) > 5
(Since 'blah' will be the same in every single row.)
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:66E8D62C-144A-4DA2-85EB-EA3ABAE1D17D@.microsoft.com...
>I know you can't use an alias in a group by, but is there any way to group
>by
> a constant in the select list? See the following northwind sample of my
> problem.
> use NORTHWIND
> select city, 'blah'
> from customers
> group BY ciy, 'blah'
> having count(*) > 5|||I just thought everything that wasn't an agragate had to be in the group by
stmt. I tried everything except for leaving the constant out of the group by
.
Thanks!!
"Aaron Bertrand [SQL Server MVP]" wrote:
> Why do you need to group by that? It doesn't make any sense. Just use:
> select city, 'blah'
> from customers
> group BY city
> having count(*) > 5
> (Since 'blah' will be the same in every single row.)
>
> "Dan" <Dan@.discussions.microsoft.com> wrote in message
> news:66E8D62C-144A-4DA2-85EB-EA3ABAE1D17D@.microsoft.com...
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment