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
5 answers

What is actually going on with HAVING clause here?

Here is the SQL Fiddle link. According to my understanding, GROUP BY would return 2 tuples. MODEL ITEM_TYPE PRICE ---------------------------- -------------------------------------…
user366312
  • 16,949
  • 65
  • 235
  • 452
-2
votes
1 answer

c# - Group by and having with two counts in Linq

How can I write the follow query with Linq in C#? SELECT MAX(A2.LINHA_PLANILHA) FROM MD_IMP_FORCA_VENDA_DADOS_A2 A2 WHERE A2.LINHA <> '0' AND TRIM(A2.SETORES) IS NOT NULL AND A2.LINHA_PLANILHA <> 1 AND USUARIO = V_USUARIO GROUP BY…
Zago
  • 11
  • 3
-2
votes
2 answers

Trouble with having clause

My tables, borrower: +----------+---------+ | name | loan_id | +----------+---------+ | Adams | L16 | | Curry | L93 | | Hayes | L15 | | Jackson | L14 | | Jones | L17 | | Smith | L11 | | Smith | L23 …
Java Enthusiast
  • 1,161
  • 2
  • 15
  • 30
-2
votes
2 answers

SQL where with date functions

i dont understand why we can use WHERE clause with date functions. For instance lets take SELECT name FROM table1 WHERE DATEDIFF(year1,year2) < 10; And its working. I thought that we cant use WHERE with functions. To do this we should use HAVING…
user3402584
  • 410
  • 4
  • 8
  • 18
-2
votes
2 answers

How to get count of grouped rows

I need to get dealers ids, which have multiple car's vendors. By example tables, I need to get id 3. I'm stuck on this query: SELECT COUNT(car.id), dealers2cars.dealer_id, car.vendor_id FROM car, dealers2cars WHERE dealers2cars.`car_id` =…
ilya iz
  • 470
  • 1
  • 6
  • 19
-2
votes
3 answers

SQL Having ,group by, that has at least 2 son , first son named X but the second son is Y

Suppose I have a tow SQL tables: Fathers id | name ------------- 1 | Clinton 2 | Gates 3 | Bush 4 | Clinton Sons id | fatherid | name --------------------- 1 | 1 | bill 2 | 1 …
-3
votes
2 answers

Selecting ALL records when condition is met for ALL

I'm having a bit of trouble with getting a select statement to work correctly. I have the following tables: recipe recipe_ingredient pantry recipe1 ingredient1 Ingredient1 recipe1 ingredient2 Ingredient2 recipe2 ingredient3 I want a…
Platt90
  • 9
  • 1
-3
votes
1 answer

WHERE "OR" HAVING Conditions instead of "AND"

i want to run sql query (mysql) and i have multiple condition in WHERE & also multiple condition in HAVING, SQL apply "AND" between WHERE & HAVING, i want to apply "OR" between. WHERE Condition 1, Condition 2 .... Condition N {{OR}} HAVING…
-3
votes
1 answer

How to use SQL to count events in the first week

I'm trying to write a SQL query, which says how many logins each user made in their first week. Assume, for the purpose of this question, that I have a table with at least user_id and login_date. I'm trying to produce an output table with user_id…
Diogenes Creosote
  • 1,922
  • 2
  • 17
  • 22
-3
votes
1 answer

What could be better SQL statement than this?

Two tables P, W are connected by Group foreign key. The bellow inner SQL returns only the table P 'names' which has only one matching 'type' in W table. The outer SQL displays name and type column values. Basically i need to retrieve only the…
SBT
  • 5
  • 2
-3
votes
2 answers

sql having statement with distinct count of a field

please i need your help on this How can i interpret this sql to linq: SELECT FK_ClassId, LectureDays FROM tbl_TimeTables WHERE (FK_ClassId = 11) group by fk_classid, lecturedays having count(distinct Period) < 7 Any help will be much appreciated…
-3
votes
2 answers

Having case multiple conditions in SQL Server 2014

I have a table 'FinancialTrans' where only 3 of those fields are needed. AcctID TransTypeCode DateOfTrans Field 4 Field 5 Field 6.... 123 TOLL 2016-06-06 123 TOLL 2016-06-02 123 TOLL 2016-04-28 123 …
user1777929
  • 777
  • 1
  • 10
  • 28
-3
votes
1 answer

How to delete frozen values from a table in MYSQL

hi I HAVE A TABLE LIKE DATE VALUE NAME 23MAY 156 CONSUMPTION_1 24MAY 122 CONSUMPTION_1 25MAY 122 COMSUMPTION_1 26MAY 122 CONSUMPTION_1 11APR 177 …
sam913
  • 43
  • 2
-3
votes
1 answer

Task with one item only

My task table has an auto-increment ID field, to my taskitem table has a foreign key 'task_ID'. The taskitem element can have numerous task_IDs (a task can have numerous items). I need to create a query that selects all task IDs from task WHERE the…
Joe Austin
  • 557
  • 7
  • 24
-4
votes
1 answer

HAVING 0 = COUNT

HAVING 0 = COUNT(1)) AS a What does this mean ? SELECT outr.* FROM Orders outr WHERE EXISTS ( SELECT * FROM ( SELECT ol.Orders_ID FROM Orderlines AS ol WHERE…
Shoaib Maroof
  • 369
  • 1
  • 3
  • 13
1 2 3
76
77