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

Join 4 tables with group by, 2 having and where clause

I have the database consists of 4 tables: users(id, "name", surname, birthdate) friendships(userid1, userid2, "timestamp") posts(id, userid, "text", "timestamp") likes(postid, userid, "timestamp") I need to get a result set of unique usernames…
Julian Kolodzey
  • 359
  • 3
  • 9
-1
votes
3 answers

Get all data from one table that's not in another table MySQL

I have a messages table: mysql> describe messages; +-----------+--------------+------+-----+-------------------+-----------------------------+ | Field | Type | Null | Key | Default | Extra …
DevOpsSauce
  • 1,319
  • 1
  • 20
  • 52
-1
votes
3 answers

SQL Server query having clause

In below query I am getting error after HAVING clause. Any help will be appreciated. Thanks in advance. Select round(TaxableAmount,0) as t, round(((TaxValue*100)/TaxPercentage),0)as t2 from VoucherTaxDetail where TaxPercentage<>0 and…
Ajay Kumar
  • 11
  • 4
-1
votes
1 answer

How to write Query with Multiple joins and having clause?

Fetch all the B_NAME having EST_ID = 10 and VALUE= 0 and EST_ID = 11 and VALUE = 1 If EST_ID exists. In the below example, the output should be B1, B2. B4 Should not be selected as it has EST_ID=12 in it. ID B_ID B_NAME EST_ID …
-1
votes
1 answer

Group By breaks Having clause

I am querying the DB to get all venues within a certain X Radius of a given latitude & longitude. Everything works good until I insert a count & group by, causing the Having clause to no longer filter out records that are SELECT locations.id AS…
neh
  • 9
  • 2
-1
votes
1 answer

Is it possible? group by Visit.VstMobile having ( (count(Visit.VstMobile)) >1 for multiple options

Let me know if this is possible in mysql query: I have referred more options in stackoverflow. group by Visit.VstMobile having ( (count(Visit.VstMobile)>=0 and count(Visit.VstMobile)<=10) or (count(Visit.VstMobile)>=10 and…
Cruzer
  • 143
  • 1
  • 10
-1
votes
1 answer

SQL In and having-clause, why do they produce different results?

Considering the following relation movie {country,major_genre,production_year, run_time, title, I'd like to list all countries except Spain, the movies produced in that country, provided there are at least two of them. I wrote two queries and they…
user3735871
  • 527
  • 2
  • 14
  • 31
-1
votes
3 answers

GROUP BY with MAX Date

The source table is: +----------------------------+ | Col A | Col B | Col C | +-------+--------------------+ | 100 | 1 | 1/2/2012 | | 100 | 2 | 1/2/2012 | | 100 | 3 | 1/2/2012 | | 100 | 1 | 5/2/2012 | | 100 | …
Rikin
  • 283
  • 3
  • 13
  • 29
-1
votes
4 answers

MySQL: GROUP BY with HAVING returns empty set, but works without GROUP BY

I have a table (cargo_route) that consists of following fields: id, truck_id, lat, lon, radius it's a shipping route where each row is each stop with lat,lon coordinates for a truck. I need to calculate a distance between each stop and my (any…
TrueStory
  • 439
  • 5
  • 17
-2
votes
2 answers

SQL Query with multiple conditions not working

Okay so this is my best attempt at making a query. It currently executes but returns nothing the other attempts have not worked. The joins are wrong I believe and I'm not sure how to fix them or do this right In this query I am trying to get the…
conor177
  • 21
  • 6
-2
votes
2 answers

How to extract duplicate orders from DB

Using SQL Server 2014. Taking the following recordset: I need to find a way to extract the ordOrderNum which is duplicates, with a different DeliveryNum. In this example, orders 93400460 and 93400467 would be extract, because they are duplicates.…
Dominic
  • 159
  • 1
  • 3
  • 13
-2
votes
1 answer

Join results using group by clause

How do i join the below 2 queries Query 1 select phn,count(*) from table 1 group by phn having count(*)>20 with the above result i need to join table 2 to get ids Query 2 select count(distinct id) from table 2 where (result_of_query1).phn=table…
Saras
  • 43
  • 5
-2
votes
1 answer

Trying to get product(s) that have been ordered the least amount of times

I want to find out the products that have been ordered the least amount of times without using order by desc or top 1 etc. My query seems to get the min calculation right but the productID and name don't match SELECT T.ProductID, ProductName,…
-2
votes
3 answers

SQL- Look for visitor that not visit second place after visit first place

i'm trying to build query that can find out who not visit a stage after he visit the first stage. Clients Table: Plays table: Tickets table: +-----+----------------------+-------------------+------+------+ | CID | PLAY | SHOWTIME …
chuks
  • 1
  • 1
-2
votes
2 answers

How do I 'join' but keep things separate in tables in MySQL?

I have two tables. Table Employees: EmployeeID (employees) LastName (employees) FirstName (employees) 1 Davolio Nancy And Table Orders: OrderID (orders) CustomerID (orders) EmployeeID (orders) 10248 …
user13153521
1 2 3
32
33