Questions tagged [having]

About the HAVING keyword in SQL.

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

Reference

Related tags

1156 questions
-1
votes
2 answers

sql using Aggregates using a combination of min(), count(), having clause

Trying to find code that will allow me to count first names by group, and then return the name with the lowest count. Sample data:- PersonGroup FirstName ------------------------ A Bob A Mary A Bob A …
Amaranth
  • 55
  • 1
  • 10
-1
votes
1 answer

MySQL - I'm trying to filter values between 1.1*min(value) and 0.9*max(value)

I have a column ride_distance_km and I've tried the following: SELECT ride_distance_km FROM ride_data HAVING ride_distance_km BETWEEN 1.1*min(ride_distance_km) and 0.9*max(ride_distance_km); Query is running, but I get 0 results which is…
Benny
  • 13
  • 2
-1
votes
2 answers

SQL UPDATE with having count

I had this table A B 1 1H 2 1H 1 1G 1 1E I need update on this table column A, that take max(a) group by B having count(*) = 2. Result will be like this: A B 2 1H 2 1H 1 1G 1 1E
Jan Papota
  • 49
  • 5
-1
votes
1 answer

Sql Developer - Use concat with GROUP BY function for COUNTING (Error ORA-00904)

I am working on a mock database for a school project and I have two tables: CUSTOMERS AND ORDERS Both tables look like this CUSTOMERS: custID, custLName, custFName, custAddress, custTown, custPostcode, custPhone, custEmail And ORDERS: orderID,…
Dylan52
  • 61
  • 2
  • 10
-1
votes
5 answers

sql union displays duplicates

image of what I want I have tried the join on x or y and it didn't work, even the group by didn't work. What almost gave me the result is the query below SELECT A.Id ,A.AccNo ,A.Name ,B.Id ,B.AccNo1 ,B.AccNo2 ,B.Name from Table1 as A left…
Cheri Choc
  • 131
  • 2
  • 11
-1
votes
3 answers

how to extend date by specific condition

query to extend the valid_till date for a month of tenants who have referred more than two times sample data: ref_id referrer_id referrer_bonus_amount referral_valid valid_from valid_till 263 5 2500 1 2015-07-05 2015-09-05 264 3 2500 …
-1
votes
1 answer

MYSQL - Get TOP 5 content grouped by value and date

I have a table with columns id date title I want to get the list of total occurrences of each title per date. So for example get: date title total 20 Apr - My Title A - 3 20 Apr - My Title B - 2 21 Apr - My Title A - 5 22…
htafoya
  • 18,261
  • 11
  • 80
  • 104
-1
votes
1 answer

Tricky SQL queries: joining, grouping, having

I have following tables for an SQL test; See SQLFiddle here > SELECT * FROM `Movie`; +-----+-------------------------+------+------------------+ | mID | title | year | director …
neurotronix
  • 221
  • 1
  • 2
  • 11
-1
votes
2 answers

SQL return data where low score is less than average low score?

I have a question on a homework assignment where I need to list the quiz number and date of those quizzes that have a low score less than the average low score. To do this I need to use a GROUP BY clause and a HAVING clause. It should look something…
progowl
  • 41
  • 9
-1
votes
1 answer

MySQL, HAVING returns single result

I'm faced with a table of player which looks like so: image of table here: I'm trying to return the players who play for an above average total playing time, I tried using WHERE in place of HAVING but I got a syntax error. My code just returns one…
-1
votes
1 answer

I want to send my local MySQL database data into the personal server daily at a certain time automatically

I want to send my local MySQL database data into the personal server daily at a certain time automatically.
-1
votes
1 answer

MYSQL: count filtered rows with having

There is two tables: CREATE TABLE `products` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `price` decimal(10,2) unsigned NOT NULL, `quantity` smallint(5) unsigned NOT NULL, `name` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB…
abdulmanov.ilmir
  • 1,325
  • 4
  • 15
  • 24
-1
votes
2 answers

sql eliminating unwanted rows

so I have made a select query like this: select distinct f.[film name] ,f.city ,case rt.[type name] when 'director' then p.[participant name] else null end 'partecipant name' ,case rt.[type name] when 'director' then…
Eden
  • 19
  • 4
-1
votes
1 answer

PHP: Combination of having and where not working in mysql query

I have a table named Messages where one entry contains the same as the following: longtitude = 4.867478333333334 latitude = 52.31819833333334 username = 'pb' If I query on the table with the…
Corey Hart
  • 173
  • 1
  • 2
  • 15
-1
votes
2 answers

Using Count, Group, join order by it returns value but not accurately

I ran this query: When i deployed the code i realised it was not given me the needed result. WHAT I WISH TO ACHIVE: GET users WHOOSE email APPEAR IN studentusers and useractivation ON THE CONDITION THAT IT THE EMAIL APPEAR IN useractivation WITH…