Re: GROUP BY clause



brenda.beltran@xxxxxxxxx wrote:
Hi everybody,

I just got to this area, so hope someone can help me with the
following issue, I will really appreciate it.

I want to query a column that is not part of the GROUP BY clause:

SELECT c.country_id,
r.region_id,
r.manag_id,
SUM(r.sls),
SUM(r.cst)
FROM country c INNER JOIN region r ON c.country_key = r.country_key
GROUP BY c.country_id,
r.region_id;

Obviously, it's complaining because r.manag_id is not in the GROUP
BY clause, but I need the result set to be as defined in the column
clause. I wonder if there is any way to have these same columns in my
query keeping my GROUP BY clause as it is now.
Hi Brenda,

maybe I didn't get the point here, but I can't see the benefit of the inline view suggestions.
If you just add the r.manag_id as a third column to your group by clause, why is the resultset different from the one you expect?

Jan

.



Relevant Pages

  • RE: Any good T-SQL quick reference recommended?
    ... The full syntax of the SELECT ... SELECT Clause ... Specifies the columns to be returned by the query. ... Specifies that duplicate rows can appear in the result set. ...
    (microsoft.public.sqlserver.programming)
  • RE: Xlocking with a select statement
    ... named query expression, order clause, update clause, lock option ... A result table or the underlying base tables are updateable if the query ... A lock can be requested for the ...
    (microsoft.public.sqlserver.programming)
  • Re: update query: still having problems
    ... "Michel Walsh" wrote: ... you should find a button that allows you to change the query "type". ... If this is what you want, fine, else, add a WHERE clause to ... SELECT Department.*, sheet1.* ...
    (microsoft.public.access.queries)
  • Re: VB-ADO-SQL Server : SQL Server performs logins after some queries
    ... If you have some joins or WHERE clause in your statement, ... Also try to minimize selection of the records using WHERE ... Incase of actual action query, ... >> of queries and I've concluded that in case of an internet conection the ...
    (microsoft.public.vb.database.ado)
  • Re: update query: still having problems
    ... "Michel Walsh" wrote: ... From the User Interface, in the toolbar, or the menu, when you edit a query, ... If this is what you want, fine, else, add a WHERE clause to limit ... SELECT Department.*, sheet1.* ...
    (microsoft.public.access.queries)