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
1 answer

Return of all rows from a query where the turnus is equal to 1

I have a Oracle Apex function which is giving a sequence of rows in a date range. The items picked in the sequence are soming from a Identifier called TURNUS. For examle: Date Range: 01-NOV-2016 to 30-NOV-2016 TURNUS is: 7 Return…
fscherbaum
  • 59
  • 1
  • 1
  • 5
-1
votes
1 answer

GROUP_CONCAT limiting to 100 values is not working

I am trying to extract a sum of modified history field limited by 100 and grouped by each account, but the query below extracts sum of all rows from CDR_Accounts with charged_quantity = 60 and does not limit to 100. table1 = table2 and these are the…
Vadym
  • 1
  • 4
-1
votes
3 answers

SQL query for finding duplicate and get others values

Here is my issue. I would like to find duplicate 'code ifls' and get the different warehouses where I get this duplicated code This is how the table looks like: | code ifls | warehouse | | 4013 | 1 | | 4013 | 2 | | …
Guibrid
  • 23
  • 4
-1
votes
2 answers

writing an query using outer join, confused by conditions needed or excluded

EMPLOYEE (fmane, minit, lname, ssn, birthdate, address, sex, salary, superssn, dno) KEY: ssn DEPARTMENT (dname, dnumber, mgrssn, mgrstartdate) KEY: dnumber. PROJECT (pname, pnumber, plocation, dnum) KEY:…
-1
votes
2 answers

Having clause being ignored

In this query, I am attempting to get a count that gives me a count of patients for each practice under given conditions. The issue is that I have to show patients who have had >=3 office visits in the past year. Count(D.PID) in the select list is…
John S
  • 33
  • 9
-1
votes
1 answer

How to get this view to SELECT DISTINCT on first column only in SQL

I am not accustomed to using SQL for View Creation, It's forcing me to use HAVING and GROUP BY, in a standard SQL statement i would use WHERE but apparently that's not allowed. I want to SELECT DISTINCT on dbo.[ShowTex Belgie NV$Item].No_ only. But…
WouldBeNerd
  • 629
  • 11
  • 29
-1
votes
1 answer

Mysql select where values not equal

getting error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't1.pard_suma LIMIT 0, 25' at line 5 NO DISTINCT error: #1054 - Unknown column…
Rytis
  • 59
  • 8
-1
votes
3 answers

using having in where clause

If I have the following table: my_table: varchar name int score and I want to do the following query: select name from my_table group by name having count(*)>3 union select name from my_table where name like '%xyz' Is there a way…
Avner Levy
  • 6,601
  • 9
  • 53
  • 92
-1
votes
1 answer

Having performance in LINQ to SQL

Placing where after group by in LINQ to SQL, works like having in T-SQL. I hope that LINQ generates having statement in result. but when I look at the output statement, I don't see any having statement. Is there any method or trick to force LINQ to…
Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
-1
votes
2 answers

Using HAVING to search for part of a string

I was wondering if it's ok to use sql HAVING to find certain rows in a table. Example: I have a table with three columns -> ID (int, primary key), type and size (varchar) One row looks like this: ID type size 1 15; 16; 17 4;…
gogo_rulez
  • 389
  • 2
  • 10
  • 24
-1
votes
1 answer

How should I structure query?

How do I find products that have p_option_id is 1 and 11. p_id p_option_id 100 1 100 2 100 3 101 1 101 2 101 11 101 12 This should return p_id 101
-1
votes
1 answer

Msg 147 An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list

I am running SSMS 2008 select A.JOBNUMBR as [Service Call], A.PONUMBER as [PO Number], sum(A.QTYUNCMTBASE*A.UNITCOST) as [Committed Cost PO], SUM(B.WS_Committed_Cost) as [Committed Cost WS], …
-1
votes
2 answers

How to SELECT only one record from a group of related records in SQL?

I want to GROUP rows together based on a field, then SELECT only 1 of those fields from each group. Say I have a ProductID which is a compound key key based on 4 fields {model, make, region, iteration}. The ProductID is always in the format…
KRob
  • 389
  • 3
  • 19
-1
votes
3 answers

mysql inner join with having

My tables are: mysql> select * from professor; +-------+--------+--------+--------+------+ | empid | name | status | salary | age | +-------+--------+--------+--------+------+ | 1 | Arun | 1 | 2000 | 23 | | …
Francis S
  • 183
  • 3
  • 12
-1
votes
3 answers

mysql how to find if at least one row from cross reference table is null or criteria

i have trouble with mysql, i dont find the way to do it maybe i dont know the good mysql keyword mysql5 +----------+------------+----------+ | ID | FOREIGNKEY | TRAINER | +----------+------------+----------+ | ... | ... | ... …
juhnz
  • 304
  • 3
  • 11