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

489 questions
-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
  • 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
  • 557
  • 2
  • 6
  • 23
-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
  • 273
  • 2
  • 11
  • 26
-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
  • 409
  • 5
  • 15
-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
  • 127
  • 1
  • 2
  • 11
-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
  • 35
  • 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
-2
votes
3 answers

Filter by number of occurrences in a SQL Table

Given the following table where the Name value might be repeated in multiple rows: How can we determine how many times a Name value exists in the table and can we filter on names that have a specific number of occurrances. For instance, how can I…
-2
votes
1 answer

Having Without Group By in MySQL

I have read multiple articles and now I am confused between 2 following statements. If we use having without group by then whole table act as Single Group. If we use having without group by then each table act as an individual Group. Which One is…
-2
votes
1 answer

select group of rows that matches all its associated items to a list

I got a table: id|name ------ 1|Tom 1|Lucy 1|Frank 2|Lucy 2|Frank 3|Frank 4|Jane 5|Robert 6|John Need result of id's where all the names associated with a specific id match to the list The list is ('Lucy','Frank','Jane','Robert','Brandon'). I've…
-2
votes
1 answer

All the customers who have spend more than 1200

I need to write a query where on this table CREATE TABLE sales ( OrderID INT, OrderDate DATE, OrderPrice INT, OrderQuantity INT, customerName VARCHAR(20) ); This is my table right…
-2
votes
2 answers

How to use distinct keyword in SQL?

I tried the following query : select class from courses WHERE distinct student having count(class)>=5 ; Basically I am trying to get all the classes that have count more than 5.On the same time I am trying not to have duplicate students. So it…
-2
votes
1 answer

How to find group which is having Status Active?

I have a id which is having more than one Accountid in a table with status Active . I need to find group of active for the particular ID . Please find my below query .is it correct or something need to modify to get better optimized result . select…
1 2 3
32
33