Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

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.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
win32
Asked:
win32
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select Site, count(*)
 from vToneAudiogramCurve
group by Side having count(*) = 2
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
select * from vToneAudiogramCurve
where Side in ( select Site  from vToneAudiogramCurve group by Side having count(*) = 2 )
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now