Solved

How can i fix this query?

Posted on 2011-02-28
5
334 Views
Last Modified: 2012-05-11

I need to know why the following command would create an error, and what could be changed to fix the error:

SELECT S_NUM, SUM(S_PHQ)
FROM      ORDER;
0
Comment
Question by:checkmofoshoduno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Assisted Solution

by:Cluskitt
Cluskitt earned 250 total points
ID: 34995938
SELECT S_NUM, SUM(S_PHQ)
FROM      ORDER
GROUP BY S_NUM
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 34995945
You need to have a GROUP BY clause so that the query knows which fields to sum together.

Try it as:
SELECT S_NUM, SUM(S_PHQ)
    FROM ORDER
    GROUP BY S_NUM

Open in new window

0
 

Author Comment

by:checkmofoshoduno
ID: 34995947
Whats wrong with the first query?
0
 

Author Comment

by:checkmofoshoduno
ID: 34995951
Got it, thankk you
0
 
LVL 3

Expert Comment

by:mehdi_javan
ID: 34995971
You can't have aggregation function with a simple field in a select statement without "group by". This is a rule.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question