?
Solved

SQL Aggregate Function Error

Posted on 2011-05-12
1
Medium Priority
?
336 Views
Last Modified: 2012-05-11
I am at a loss with this one.

Column 'StockQuoteHeader.SQHQuoteID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I want to Group By Sales and the order by date.

"Select Distinct SQHQuoteID, Count(SQHQuoteID), SQHTotalDollar, SQHFollowUpComments, SQHCustomerName, SQHCustomYes, SQHEndUserName, SQHContactName, SQHCreatorUsername, SQHCreatorDateTime, SQHRegion, SQHSalesPerson from StockQuoteHeader where SQHWonLostOpen='Open' and SQHStatusCode='35' group by SQHSalesperson order by SQHCreatorDateTime desc "

Thanks
0
Comment
Question by:ParisBP
1 Comment
 
LVL 41

Accepted Solution

by:
Sharath earned 1000 total points
ID: 35750551
try this.
SELECT DISTINCT t1.SQHQuoteID, 
                t2.cnt_SQHQuoteID, 
                t1.SQHTotalDollar, 
                t1.SQHFollowUpComments, 
                t1.SQHCustomerName, 
                t1.SQHCustomYes, 
                t1.SQHEndUserName, 
                t1.SQHContactName, 
                t1.SQHCreatorUsername, 
                t1.SQHCreatorDateTime, 
                t1.SQHRegion, 
                t1.SQHSalesPerson 
  FROM StockQuoteHeader AS t1 
       INNER JOIN (SELECT SQHSalesperson, 
                          COUNT(SQHQuoteID) AS cnt_SQHQuoteID 
                     FROM StockQuoteHeader 
                    GROUP BY SQHSalesperson) AS t2 
         ON t1.SQHSalesperson = t2.SQHSalesperson 
 WHERE t1.SQHWonLostOpen = 'Open' 
       AND t1.SQHStatusCode = '35' 
 ORDER BY t1.SQHCreatorDateTime DESC  

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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
Course of the Month14 days, 2 hours left to enroll

807 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