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

Oracle Having > Single Row

I have an Oracle query, which has something to the effect of Having Count(field) > (Long SQL statement that returns one row) Both sides of the query work alone, but together I get a "not a group by" expression. When replacing the long SQL statement…
Shane Chin
  • 578
  • 2
  • 9
  • 20
-2
votes
1 answer

Aggregation of query in sql

I have table, like: Id Account Date Amount 1. ad@ind 07.11.2022 354 2. ad@ind 10.11.2022 586 I need to find record, where is maximum number of month and get amount in this date. How is it to do? Max(date) does'nt fit, i need number…
-2
votes
1 answer

SQL ignoring where condition in having clause

Actually SQL is ignoring the where condition in my having clauses. It doesn't matter what I fill in there. It always finds "all" results. SELECT `status`, count(*) AS count FROM `wa_re_jo` WHERE EXISTS ( SELECT * FROM…
spyro95
  • 136
  • 9
-2
votes
1 answer

Data Validation using SQL

I am attempting to write a validation report for a client that validates a number of rules for a workflow. Test Matrix as follows (I've left out the PROJECT portion because that could just complicate things and if I get it working for…
Vaesive
  • 105
  • 1
  • 11
-2
votes
2 answers

How does having clause filter rows in mysql?

As I know HAVING clause is used to filter rows for each group. I have a table that stores scores of students. create table sc ( `classid` int, `studentid` int, `score` int ); Here is the sample data: +---------+-----------+-------+ |…
-2
votes
1 answer

Which index(es) should be used in these queries?

I have a question about SQL indexing in my theory class. It asks me to choose which column should be indexed to optimize these 2 queries: (This is 'paper' question so I am not provided the database to test these indexes with EXPLAIN) 1, First…
-2
votes
1 answer

What's wrong with the having clause in my query?

Select facid, sum(slots) as total from cd.bookings group by facid having total > 1000 order by facid;
-2
votes
1 answer

How do you use having for multiple conditions?

In the following codes, how do you exclude members's spending that's larger than $500 for each year (instead of total spending for all years)? select Year ,month ,memberkey ,sum(spending) as spending from table1 group by 1,2,3
BurtBee
  • 19
  • 1
  • 4
-2
votes
1 answer

how to find o/p all the student who are enroll in 2 or more courses in sql server using group by?

i have a table name as testtabl1 now i want to find all the student who are enroll in 2 or more courses, in this sid is the student id and cid is the course id table structure create table testtabl1(Sid int,cid int,years varchar(20)) insert into…
Deepak Jain
  • 137
  • 1
  • 3
  • 27
-2
votes
1 answer

MYSQL insert into + select + CASE + delete not working

I have 2 identical tables DATES and DATES_ARCHIVED I want to select in the DATES table all the rows that have dates that are older than current date -88 days, then insert those rows into the DATES_ARCHIVED. I have created a CASE for this. Then after…
PAPADOC
  • 45
  • 1
  • 6
-2
votes
1 answer

What is wrong with HAVING and GROUP BY in MYSQL?

Get the makers who produce only one product type and more than one model. Wrong Answer: `SELECT` `DISTINCT` maker from Product `GROUP BY` maker `HAVING` (`COUNT`(`DISTINCT` TYPE) = 1 `AND` `COUNT`(`DISTINCT` model) > 1) Right Answer: `SELECT`…
sapio_l
  • 21
  • 7
-2
votes
1 answer

GROUP BY with WHERE clause in SQL Server

I'm trying to build a T-SQL query to list some columns and group values with certain criteria under a different name. This is what I have in my table: Category | Verdict | Requests -----------|--------------|---------- Category1 | Allowed …
Frosa
  • 37
  • 1
  • 1
  • 9
-2
votes
1 answer

I need to compare the sum of one table to the sum of another table and only display when one is greater than the other

here is my code select sum(IV.total) as total, IV.sono, sum(SO.total) as total2 from tblInvoiceDetail as IV left join tblSO as SO on IV.sono=SO.sono where IV.sono not in (108428,108368) group by IV.sono having…
user3520445
  • 207
  • 2
  • 6
-2
votes
1 answer

How to use an sum() function without group by?

I just have to omit those records whose sum of sales in all 53 weeks is 0 and would need the output without group by
shyam iyer
  • 57
  • 1
  • 7
-2
votes
3 answers

SQL Having count logic

i need help on HAVING COUNT , i have a result set of data below: CREATE TABLE #tmpTest1 (Code VARCHAR(50), Name VARCHAR(100)) INSERT INTO [#tmpTest1] ( [Code], [Name] ) SELECT '160215-039','ROBIN' UNION ALL SELECT '160215-039','ROBIN' UNION…
japzdivino
  • 1,736
  • 3
  • 17
  • 25
1 2 3
76
77