Solved

not contained in either an aggregate function or the GROUP BY clause ERROR

Posted on 2008-06-14
3
3,443 Views
Last Modified: 2012-08-14
I am trying to get a list of the top 10 items viewed solutions in my knowledge base. I do this by getting the count of records in the solution_rating__c table joined to the solution table record which has the KB article. The solution_rating table gets a new insert every time the article is viewed. So I tried to put together the query below, but can't figure out how to get the results to sort by the aggregate count of soltuion_ratings for each solution record.

Thanks
select top 10 count(sr.solution__c ) as thecount, sr.solution__c ,
s.solutionname, p.[name]
from dbo.solution_rating__c sr
join solution s on sr.solution__c = s.id
left outer join dbo.product_group__c p
on s.product_group__c = p.id
group by  thecount, sr.solution__c ,s.solutionname, p.[name]

Open in new window

0
Comment
Question by:advlgx
[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
3 Comments
 
LVL 6

Expert Comment

by:DocCan11
ID: 21786144
if you want to use the TOP clause you should have an order by clause so it sorts them..
0
 
LVL 2

Accepted Solution

by:
osiara earned 500 total points
ID: 21786146

select top 10 thecount, solution__c, solutionname, name from (
select count(sr.solution__c ) as thecount, sr.solution__c ,
s.solutionname, p.[name]
from dbo.solution_rating__c sr
join solution s on sr.solution__c = s.id
left outer join dbo.product_group__c p
on s.product_group__c = p.id
grou p by  thecount, sr.solution__c ,s.solutionname, p.[name]
) as pom
order by thecount

Open in new window

0
 

Author Closing Comment

by:advlgx
ID: 31467220
Awesome, thanks
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

635 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