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
2 answers

SQL Group By and Having display fields

I’m trying to pull the people records associated with 405B folders where there is more than 1 folderpeople record. I’ve used the following SQL to get the counts, but what I can’t figure out is how to pull the actual people information ,p.namefirst,…
DEwok
  • 73
  • 2
  • 3
  • 11
0
votes
1 answer

HAVING clause not working after server update

We have just made a major upgrade in mysql version from 5.0.51 to 5.6.22 and I have just noticed that one of my queries no longer works properly. SELECT p.id AS product_id, p.code, p.description, p.unitofmeasure, p.costprice, …
prevailrob
  • 275
  • 3
  • 11
0
votes
2 answers

What does 1 and 2 with HAVING clause mean in SQL query in Oracle?

I created an employee table having attributes : deptno and salary in Oracle DBMS. I executed this query : SELECT deptno, SUM(salary) FROM emp GROUP BY deptno HAVING 1 > 2 ; I thought that 1 and 2 are referring to the columns "deptno" and…
A_J
  • 977
  • 4
  • 16
  • 44
0
votes
2 answers

Can I write a condition on a single column name of a relation in HAVING clause

Considering the following relational schema customers(id, name, age, address, salary) I tried a query SELECT SUM(salary), age FROM customers GROUP BY age HAVING age > 23 ; ...(1) I was surprised to see that it…
A_J
  • 977
  • 4
  • 16
  • 44
0
votes
1 answer

SQL/PHP: Update result from select query

I've been trying to get this working forever now and I can't seem to get it to work. I need to update a column in my tours table if there are less than 8 reservations for it in the tours_reservations table when the tour is next week. I have a select…
J_vdv
  • 49
  • 1
  • 3
  • 9
0
votes
0 answers

MySQL sub-queries using WHERE and HAVING clauses

Create three queries using tables Employee_T and hoursWorked_T. Returns a single column and single row in the outer query's WHERE clause Returns a single column and single row in the outer query's HAVING clause Returns a multi-column table in the…
0
votes
3 answers

MySQL having if

I'm having trouble with a MySQL query. If the label is "5" then I only want records where there is more than 10 of them for the current day, but any number of rows for other labels. What is the best way to accomplish this in the query? SELECT…
Peter Sands
  • 3
  • 1
  • 1
  • 2
0
votes
2 answers

Using having in SQL

I want to merge the following queries to get the answer I want. But I don't seem to get it right. Query 1: select a.idlisting, count(p.idpostulant) as Total_postulants from postulations p inner join listings a on p.idlisting = a.idlisting where…
Pietro
  • 125
  • 1
  • 3
  • 11
0
votes
1 answer

How to select faulty records?

I'm investigating an error in one of our tables of a geographical database. Given the table below, the DistrictName and DisId should always have the same combination (i.e. Bronx = 11, Manhatten = 14), but some records have a different DisId (while…
Lave Loos
  • 1,252
  • 1
  • 11
  • 15
0
votes
1 answer

update only records with a max value using group by

I have some data, and wherever the server_id, product_id, and polled_at date match, i want to set updated_by to 2 (only searching rows where updated by is already 1). I have been messing with my code for a while, but can't figure it out. Please help…
Candice
  • 25
  • 6
0
votes
2 answers

How to fetch ID from database if particular column has both value

Database columns, Now i want to get those Product IDs only those having OPTIONS_VALUES_ID (12 and 31) SELECT DISTINCT pa.products_id,options_values_id,options_id , COUNT(options_values_id) FROM products_attributes pa WHERE …
Ronald Joseph
  • 45
  • 1
  • 13
0
votes
1 answer

SQL for Top10 Companies by Hits on Company Profile - or a better solution?

I browsed summaries for all 500+ answers related to this question but found no apparent SQL solution to my problem. Maybe there is none. I wish to display a Top10 Companies by Hits on Company Profile from nnn to nnn time period. MySQL Table to…
0
votes
1 answer

Difference b/w 'HAVING NOT EXISTS' and 'MINUS'

HAVING acts like a where clause and EXISTS checks for the rows that exist for the given row or not. So, when we use HAVING NOT EXISTS it should have the same functionality as MINUS which eliminates the common rows from first table. But in an…
ethan
  • 309
  • 1
  • 7
  • 19
0
votes
1 answer

UPDATE with HAVING Clause calculated

I am trying to do an updated statement based on a select that uses a HAVING clause and calculated field in MySQL. My Select is: SELECT FLOOR( IF( file_real_id, file_real_id, file_id ) /5000 ) AS fldrid, file_id FROM Files WHERE srv_id =2 HAVING…
0
votes
2 answers

Column ALIAS not recognized in HAVING clause, unkown column error

SELECT u.*, zz.contid, zz.lng, zz.lat, zz.zip, zz.city, zz.state, (**calc distance**) AS distance FROM contacts zz INNER JOIN users u ON zz.id = u.id WHERE cond1 = 1, cond2=2, etc.. GROUP BY u.id HAVING MIN(distance) < 100 Error: unknown column…
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231