Questions tagged [having-clause]

About the HAVING keyword in SQL.

(Should really be: )
The HAVING clause is the equivalent of WHERE after applying aggregate functions.

Reference

Related tags

494 questions
0
votes
1 answer

Can i use string type with having clause(Like ....having sex='male')

select country,count() from employee group by country having id<4; this query works fine but when i use select country,count() from employee group by country having sex='male'; showing error :-ORA-00979: not a GROUP BY expression Why??
0
votes
2 answers

SQL - HAVING Clause in depth

I'm trying to understand what condition can be placed after the having clause - it is usually a condition, that uses the functions from the select statement, but it also can contain a column, that is typed in the select statement. Here's an…
Rio
  • 99
  • 4
  • 12
0
votes
1 answer

MS Access Having Clause

Alright so I understand the point of the HAVING clause. I am having an issue and I am wondering if I can solve this the way I want to. I want to execute one query using ADODB.Recordset and then use the Filter function to sift through the data…
Maxs728
  • 591
  • 2
  • 8
  • 18
0
votes
0 answers

SQL Server: Find duplicates using group by and having count than delete them all but not first

I have to maintain an old MS SQL 2008 database with tons of records. I notice that about 90% are duplicates. So what is the best way to remove only the duplicates. I used... SELECT [Col1],[Col2],[Col3],[Col...], COUNT(*) AS [DuplicateCount] FROM…
GertR
  • 75
  • 1
  • 7
0
votes
1 answer

WHERE vs HAVING calculated field with multiple IFs/LIKEs

If i'm not wrong when using having, the query is executed without any filters then the code go over all the result to apply the filter. But in this case I'm using multiple Like//If to calculate my order. I was wondering what would be better…
Jordan Daigle
  • 424
  • 4
  • 12
0
votes
2 answers

Rewriting subquery has having clause into a join?

I have a table with columns like this; site, chromosome, strand. The pair of site and chromosome should be unique while they can have more than one strand. Before loading the data, I found that some of the sites have more than one chromosome, which…
microbe
  • 3
  • 2
0
votes
2 answers

Perform Union/OR Operation between where clause and having Clause

I am working on implementation for a SQL which should display results with Union operation between Where and Having Clause. For example, Select * from table where col1= 'get' group by col2 (OR/UNION) having avg(col3) >30 . This is not valid but…
TechJump
  • 79
  • 1
  • 12
0
votes
1 answer

SQL - MAX returns multiple results when querying more than one column

This is my first post because I can usually find answers just by browsing the other questions here, but I have tried following instructions on a few of the suggestions, like this, this, this or this, but to no avail. Ultimately I want to use my…
0
votes
2 answers

Mysql query with group by having

I have a table with 3 columns: id, sentence and language. So sentences can be either in English and German, IDs are assigned to sentences with same meaning but different languages, like ID | sentence | language 1 | Hello | en 1 | Hallo |…
boreas
  • 1,041
  • 1
  • 15
  • 30
0
votes
2 answers

Sql - struggling with count/having query based on several joins

I'm struggling to get my query working. Basically, what it should do is only return vacancies that haven't been filled. For example, a vacancy can have a pre-determined limit of 5. To fill this, it will need to have a mixture of 5 active or pending…
user275074
0
votes
2 answers

SQL- HAVING Clause Issue

I'm trying to use the MAX() function as a subquery to filter results of my greater query by the last couple of whole years. I realized this was a little bit more complicated than what I initially thought it would need so I created a much simpler…
plankton
  • 369
  • 5
  • 21
0
votes
2 answers

How to use having on un-aggregate field in MySQL?

select xx as fieldA from ... group by xxx having fieldA is not null I found that having has no effect
wamp
  • 5,789
  • 17
  • 52
  • 82
0
votes
1 answer

Longitude latitude query but only rows that match column in same table

I've looked and looked and tried and tried with no success. I have a query that I use to display users within a certain distance range. It works great, but it returns all users from my users table, and I want it to only return users where the value…
0
votes
1 answer

IS NOT NULL in Cloudera-Impala

I'm new on Impala, and I'm trying to write a query where one field is SUM(X), and I want to put a condition on that field. When I used that query in MySQL, "HAVING SUM(X) IS NOT NULL" worked great - does anyone know what's the equivalent in…
Bramat
  • 979
  • 4
  • 24
  • 40
0
votes
2 answers

Having With Sub query MySql

I want to select which model car is involved in most accidents. i am using the following query but i get a syntax error. please someone tell me whats wrong.. select car.Model from car join car_accident_involved on…
Mehroz Irshad
  • 287
  • 1
  • 5
  • 14