473,383 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Group by in select problem

167 100+
I am having problems with a query whenever I use 'group by', it tells me that the other columns I have are not part of an aggregate function.
Example:
Expand|Select|Wrap|Line Numbers
  1. Select Acctnum, Date, Dept, sum(SPAmt)
  2. From TableA
  3. Group by Dept
The result I am trying to get is a row for each Dept with the total of SPAmt for that Dept. However, when I run the select, it gives an error and says 'Acctnum' is not part of an aggregate function. What am I doing wrong?

Thanks
May 27 '09 #1
1 1694
NeoPa
32,556 Expert Mod 16PB
I'm not sure where this would be confusing so I'll explain as clearly as I can.

GROUP BY, as a clause, ensures that a list of one or more input records are processed to provide a single output record.

Any item within the GROUP BY clause is one that, by definition, must be the same across the group (of input records). Thus SELECTing any such field makes sense without aggregation.

Aggregation is a process that returns a single value from one or more values provided. Examples of aggregate functions include Sum(), First(), Max(), etc.

A GROUP BY query needs either a GROUPed by item or an aggregate item. In your SQL you refer to AcctNum without any aggregation or GROUP BY. There is no way for the SQL engine to interpret or process this. Hence the error message.

Does this make things clearer?
May 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
10
by: Randell D. | last post by:
Folks, I have a SELECT that returns with multiple records - It works when I have a LIMIT clause but when I try to include a GROUP BY clause, the select returns nothing (ie no records, no...
3
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
2
by: JJA | last post by:
Please advise on how to get the GROUP BY coded in an acceptable way: DECLARE @LO INT DECLARE @HI INT DECLARE @StartDate varchar(10) DECLARE @EndDate varchar(10) SELECT @StartDate =...
4
by: Stefan Bauer | last post by:
Hi NG, I have problem... I'm currently using UDB v8.1 for Linux. Here is the table "test": ID1 ID2 ID3 VALUE ----------------- 1 0 1 23 1 0 2 9
12
by: Bill Moran | last post by:
Hey all. I've hit an SQL problem that I'm a bit mystified by. I have two different questions regarding this problem: why? and how do I work around it? The following query: SELECT GCP.id,...
10
by: Rudolf Bargholz | last post by:
Perhaps some kind soul could help me out with an SQL I have been trying all day to get to work, where one colum is just not summing up the way I want it to. I have the following data GRP_SEQ ...
1
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
5
by: Seb | last post by:
I want to count activity in a given month. I'm trying to do so with the linq code below however it reports: Error 1 'a' is inaccessible due to its protection level var ActivityByMonths = from a...
2
by: RolfK | last post by:
Dear ALL, I need some help on xsl:sequence. I'm using the Altova XSLT processor, but I'm quite confident it is not an processor issue. It's probably my bad knowledge of xslt 2.0. I have probably...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.