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

494 questions
-1
votes
1 answer

Select field 1 Where Field 2 ='value1' And field 2 ='value2' when Field 1 is Same

I am currently having troubles with filtering my SQL records. I need something like what it results in the following concept: Table is A B 1 1 1 3 2 1 2 2 2 3 2 4 3 1 3 2 I want to select value of A , where B=1 and B=2 And B=3…
-1
votes
2 answers

SQL Query to get rows that have 3 unique values in column

Blanking out on how to get this data: I have a table like this: ==================== ID | Source ==================== 1 | google 1 | fb 1 | linkedIn 1 | linkedIn 3 | linkedIn 3 | fb I want to return all the Ids…
CD Brian
  • 43
  • 7
-1
votes
2 answers

How to add condition on virtual column in mysql?

I want to add a condition for the tbl_restaurant_featured_history.id column but I can't add that condition in where clause because It shows an error saying Unknown column 'featured' in 'where clause' and If I add a condition featured is not null …
-1
votes
1 answer

Syntax differences between Mysql and SQL Server

Description: Julia asked her students to create some coding challenges. Write a query to print the hacker_id, name, and the total number of challenges created by each student. Sort your results by the total number of challenges in descending order.…
Happy Bing
  • 11
  • 4
-1
votes
2 answers

SQL help for Group by clause on one field and specific record count condition on another field

Need help getting a SQL. I have below kind of table. Need below result records based on the fact that they have "abc" and "def" in Field2 just one occurrence of each value not more no other value apart from "abc" and "def". Expected…
PMDEV
  • 15
  • 4
-1
votes
1 answer

SQL How to ask for a value multiply times in an Query

Good evening folks! Following Problem, I have three tables: Create TABLE Suppliers ( SID integer, sname varchar(50), adress varchar(50), PRIMARY KEY (SID) ) Create TABLE Parts ( PID integer, pname varchar(50), color varchar(50), PRIMARY KEY…
-1
votes
1 answer

MySQL Group By: How exclude group if at least one row contain value?

How do you filter out a group in the HAVING clause if at least one row of the group meets some condition? For example, If have the following table: And I want group by id1 and id2 and exclude any group where at least one of its rows has "value" in…
oneCoderToRuleThemAll
  • 834
  • 2
  • 12
  • 33
-1
votes
3 answers

Using Sum of Group Concat in Having clause

I want to find all ids of which sum of group_concat is 0 . Here is simplified table from mine. ╔════╦════╦══════════════╦ ║ id ║ did║ group_concat ║ ╠════╬════╬══════════════╬ ║ 1 ║ 1 ║ 1,1,1 ║ ║ 2 ║ 1 ║ 0 ║ ║ 3 ║ 2 ║ 1,-1 …
user13053989
-1
votes
2 answers

how to get mysql values based on left join condition

job table 1.id 2.status = 'active' 3.name repair table 1.repair id 2.job_id 3.process = 'yes|no' 4.status = '1|2' job table id name status 1 test active 2 check active repair table repair_id job_id process status 1 …
Durai Raj
  • 47
  • 1
  • 1
  • 8
-1
votes
1 answer

Postgres group by having at least 1 row with status='started'

I need to perform a group by and only including if at least one observation matches the constraint. Like I have tried to describe below. SELECT {some variables} FROM my_table GROUP BY A HAVING {at least 1 row with status='started'} My initial guess…
Peter Mølgaard Pallesen
  • 1,470
  • 1
  • 15
  • 26
-1
votes
1 answer

Sqlite3 GROUPBY with HAVING and ORDER BY not working

I have a SQL query that is calculating the correct output, and is even doing the order by correctly, however it is not executing the having clause. am i doing something wrong? It is not filtering the percentages at all. select table1.name as theme,…
zelda26
  • 489
  • 2
  • 10
  • 33
-1
votes
2 answers

TSQL -- find records in table with multiples in one column, and at least one specific occurrence of a value in another column

TSQL -- find records in table with multiples in one column, and at least one specific occurrence of a value in another column If I have: ourDB.dbo.ourTable with col1 and col2 and col 3 I want to find occurrences such that * A value of col1 occurs…
JosephDoggie
  • 1,514
  • 4
  • 27
  • 57
-1
votes
1 answer

Get Count of rows fulfilling a condition group by a column with min and max

I want to get count of people who leave on time in some specific date range in an attendance scenario. For that I need total employees who marked their attendance when they left office. If an employee logged at-least two times (1 for in and 2nd for…
AdPy
  • 176
  • 9
-1
votes
2 answers

How to read multiple strings and dates in mySQL table in one read statement?

I have a mySQL table similar to following example : DOC_OwnerID DOC_type DOC_start_date DOC_end_date 100 JANUARY 1/1/2017 12/31/2018 100 JANUARY 1/1/2018 12/31/2019 100 DRIVER …
PCG
  • 2,049
  • 5
  • 24
  • 42
-1
votes
2 answers

MySQL query: How to get the trending posts ordered by latest submission date

I am trying to get the latest trending posts, which are suppose to be the post with the highest number of Views, and for that I am using the following MySQL query: SELECT p.id, p.date, COUNT(v.post_id) views FROM posts p JOIN…
Xenotic
  • 51
  • 1
  • 9