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

489 questions
-2
votes
1 answer

SQL - how to filter for PRODUCT_AGE less than 12 in this query. My example returns an error

I am trying to get products groups that have products with a PRODUCT_AGE less than 12 months old. Here is my current query: SELECT MIN(SHIP_TABLE.SHIPDATE) FIRST_SHIPPED, PRODUCT_TABLE.PRODUCT_GROUP_ID,…
-2
votes
1 answer

How to implement a WHERE clause on a MySQL query

I have this database table “ MyTable” contain data as shown below, I want to fetch data from it using where clause as so that I can have a view as on “MyView2. MyTable StudentID courseID scores term Academic year A001 PHY …
f2k
  • 99
  • 9
-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
  • 17,582
  • 55
  • 198
  • 392
-2
votes
1 answer

Why are aggregates not allowed in SQL where clause

SELECT SUM(salary) FROM EMPLOYEE WHERE SUM(salary) > 10000; causes error, I know that it needs to be put in HAVING clause. My question is why? As in root cause for this syntax choice in SQL language design.
Abe
  • 7,490
  • 9
  • 42
  • 72
-2
votes
1 answer

Having trouble with HAVING COLUMN in mysql search

having trouble with HAVING clause of a column which exists SELECT COUNT(*) AS `numrows` FROM (`customers`) LEFT JOIN `parent_companies` AS j2ee39a6a ON `j2ee39a6a`.`id` = `customers`.`parent_company_id` WHERE `customers`.`is_approved` = 0 AND …
Blakdronzer
  • 290
  • 3
  • 13
-3
votes
3 answers

How to get common value based on a column from a table sql

I have a table. the screenshot is given bellow: There have two columns item_details_id pay_method_id In item_details_id there have 1,2,1 data. On the other hand pay_method_id have 1,1,3 data. I want to get only common values of pay_method_id…
Mehedi Hasan Siam
  • 1,091
  • 2
  • 9
  • 24
-3
votes
2 answers

MYSQL Query Using HAVING Not Work Correctly

SELECT user_data_fields.user_id, CONCAT(",", GROUP_CONCAT(CONCAT(user_data_fields.field_id, "-",user_data_fields.value)), ",") AS var, survey_answers.question_id, survey_answers.answer FROM user_data_fields JOIN survey_answers ON…
yasen
  • 19
  • 8
-3
votes
1 answer

Working with In command and group by clause

I am trying to fetch some data out of two tables (department and person), my work is basically with in clause. Could anybody help me identify the problem in the following query? from email.department, email.person where person.works_in in (select…
Muhammad Usman
  • 123
  • 1
  • 1
  • 10
-4
votes
2 answers

want to find out the book_id which is written by a single author only and p_id=1

I have 3 tables. This is the Person table: This is the Car table: This is Person_car table hloding join column for many to many: Now i want to find out the c_id (car id) that is owned by a single person and p_id=1. That means in this scenario i…
sourav
  • 29
  • 4
1 2 3
32
33