Solved

Group By, Aggrigate function ?

Posted on 2006-11-14
3
292 Views
Last Modified: 2012-06-21
Hi, I have written the SQL:

select * from vToneAudiogramCurve
group by Side having count(*) = 2

Then I get the error:
Column 'vToneAudiogramCurve.Client_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

The reason I wan to groop it, and use the having count(') = 2 is that I only want to see results that is in 2 times. How can I get this to work ?
0
Comment
Question by:win32
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 17938449
select Site, count(*)
 from vToneAudiogramCurve
group by Side having count(*) = 2
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17938453
select * from vToneAudiogramCurve
where Side in ( select Site  from vToneAudiogramCurve group by Side having count(*) = 2 )
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17938464
you need to specify all the columns except those used for the aggregate functions, for eg, if you have columns Col1, col2 ...Coln
then

SELECT Col1,Col2
FROM urTable
GROUP BY Col1,Col2
Having Count(*) >1
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now