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

Reference a FROM alias in HAVING

Newbie to sql here. I am trying to select only tuples whose values in one column are larger than the average of that column. The problem is, the relation I am working with is created in the FROM clause, because I need to add a transformation (and…
Spencer
  • 860
  • 8
  • 16
0
votes
1 answer

SQL having 2 types but no more

Having a table with two columns, carrier and networktype I want to select the carrier, networktype and the count of rows that have exactly 2 specific networks types and no others. So given the following table Carrier NetworkType Count 302720…
Hiro2k
  • 5,254
  • 4
  • 23
  • 28
0
votes
0 answers

SQL: Counting the result of a select statement

I have maybe a dumb question? Anyways, I can't figure it out. blah blah GROUP BY cp.c, cp.r HAVING COUNT(*) = (SELECT COUNT(cp.r) FROM cp WHERE cp.r IN (SELECT cr.r FROM cr …
user963070
  • 629
  • 2
  • 19
  • 24
0
votes
0 answers

MSAccess with a WHERE Clause to only affect one of the LEFT JOINS

I have a 'busy' MSAccess SQL Query which I want to display a full set of results. In the main table 'JobsMain' a result is either a Maintenance Job or it is not. The following query (MSAccess Relationships:…
0
votes
1 answer

grails executeQuery with Acos/having/cross-Join

I want to execute a query for zip-search. I've got a domain-model like this: class Zip_data { int zc_loc_id String zc_zip String zc_location_name double zc_lat double zc_lon static constraints = { zc_loc_id() zc_zip() …
Der_V
  • 177
  • 1
  • 16
0
votes
4 answers

SQL Find Count of Records by Day and By User

I am trying to find the count of days listed by person where they have over 100 records in the recordings table. It is having a problem with the having clause, but I am not sure how else to distinguish the counts by person. There is also a problem…
Klay
  • 183
  • 5
  • 12
0
votes
1 answer

No Results returned for ROW_NUMBER() query

I am getting "no results returned" for the following query: SELECT Referer FROM (SELECT ROW_NUMBER() OVER (ORDER BY CT.Referer ASC) AS RowNum, CT.Referer, CT.LastModified FROM ClickTrack CT JOIN …
0
votes
3 answers

Conditional Count in SQL

The following is my code SELECT b.fulldate, b.userid, Count(a.isclanmatch) FROM (SELECT fulldate, realmatchid, isclanmatch FROM gro_int.int_match WHERE ( fulldate BETWEEN…
0
votes
2 answers

Delete Rows brought back from a Select statement that contains a having and group by clause in Oracle

I have this select statement: SELECT d.idcprefix, d.orgdept, d.idcseq, d.subcont, d.actualcomp, COUNT (*) AS "No Duplicates" FROM DCS_IDC, DCS_IDC z WHERE D.IDCPREFIX = z.idcprefix …
iandavidson1982
  • 190
  • 3
  • 17
0
votes
1 answer

Show duplicated data with HAVING COUNT in MYSQL and PDO

I need to show count of similar data from rows in one table to make a report, I have already this script but can't make it works...I see that with HAVING COUNT I can show repeated data and counting form row but I can make it
0
votes
2 answers

How to write this SQL query using having clause?

My database schema is like following table - X has following 3 columns docid(document id), terms(terms in document), count(number of terms of occurence of the term for specific docid) docid terms count How to extract the information as for the…
Surjya Narayana Padhi
  • 7,741
  • 25
  • 81
  • 130
0
votes
1 answer

Using aliases names of columns in where clause

I have given a alis name for all my fields in the select clause. I am not able to use these names in my where clause. I tried to use having clause, but it takes more time then usual where clause. Is there any solution for this ?
Hacker
  • 7,798
  • 19
  • 84
  • 154
0
votes
1 answer

Having trouble with grouping rows - MS SQL 2008

I have a product table which has some duplicate records. I need to get primarykeys atfer grouped them according to names and types DECLARE @Products TABLE ( pkProductId INT, productName NVARCHAR(500), productType INT ) INSERT INTO…
0
votes
0 answers

Pagination doesn't work with the HAVING clause in Zend Framework 2

I've implemented a pagination similar to how it's shown here: Search\Model\CourseTable class CourseTable { const RELEVANCE_TITLE = 5; const RELEVANCE_DESCRIPTION = 2; const RELEVANCE_MIN = 3; protected $tableGateway; public…
automatix
  • 14,018
  • 26
  • 105
  • 230
0
votes
1 answer

Mysql Group By, Order By, Count, Having Min() combination

I have a table with a lot of address records. New data is added to the table and I want to find all the new records that match existing name, postcode, street and which have been assigned to the same client_id (1) along with certain other criteria…
John Smith
  • 11
  • 3