?
Solved

How can i fix this query?

Posted on 2011-02-28
5
Medium Priority
?
345 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 1000 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 1000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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