win32
asked on
Group By, Aggrigate function ?
Hi, I have written the SQL:
select * from vToneAudiogramCurve
group by Side having count(*) = 2
Then I get the error:
Column 'vToneAudiogramCurve.Clien t_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 ?
select * from vToneAudiogramCurve
group by Side having count(*) = 2
Then I get the error:
Column 'vToneAudiogramCurve.Clien
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
then
SELECT Col1,Col2
FROM urTable
GROUP BY Col1,Col2
Having Count(*) >1
where Side in ( select Site from vToneAudiogramCurve group by Side having count(*) = 2 )