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

Selecting rows from a table with specific values per id

I have the below table Table 1 Id WFID data1 data2 1 12 'd' 'e' 1 13 '3' '4f' 1 15 'e' 'dd' 2 12 'f' 'ee' 3 17 'd' 'f' 2 17 'd' 'f' 4 12 'd' 'f' 5 20 'd' 'f' From…
SP1
  • 1,182
  • 3
  • 22
  • 47
-1
votes
1 answer

Conditional SQL Query Which Sums ALL TimeEntires of Related Task if any TimeEntries Updated in Last 10 Days

I have a database with columns timeEntryIDs (Primary KEY), taskAssignmentIDs, Spent(Sum of two columns product), and updatedAT. It has multiple timeEntries for every taskAssignmentID all added/updated at different dates. I am trying to build an…
RdnCdn
  • 173
  • 1
  • 8
-1
votes
1 answer

SQL Refer to alias in subquery

I want to query a table which looks like this: customer_id (INT), transaction_date (DATE), income(INT) I'm trying to create a table which shows the sum of income per distinct customer_id, except for customers which made transactions ONLY in 2014. My…
Fizban
  • 41
  • 4
-1
votes
2 answers

MySQL: Using JOINS with WHERE clause to get all records from one table and available records from the other

I am tryin to run a SQL query as below SELECT…
PeakGen
  • 21,894
  • 86
  • 261
  • 463
-1
votes
1 answer

How to count number of duplicated items in my from relational table

I have order and a product tables. The order table looks like this: uid id ref order_id --- -- ------ -------------- 1 3 abc. 112 2 3 def 124 And the product table looke liks this uid id sku order_id --- -- ------ …
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95
-1
votes
2 answers

MySQL query to find complete intersections

Imagine we have two tables: clientOffices that have a list of offices that each client has. clusters are groups of cities clientOffices ----------------------------- clientId | office ----------------------------- 1 London 1 …
-1
votes
1 answer

COUNT in a WHERE statement SQL

My Table consists of 3 columns; id, state, carColour, and over 1mil rows. I want to return all states which have more black cars than white cars. I have tried: SELECT state FROM table WHERE state IN (SELECT state FROM table …
broccoli
  • 25
  • 6
-1
votes
1 answer

Having Without Group By in MySQL

I have read multiple articles and now I am confused between 2 following statements. If we use having without group by then whole table act as Single Group. If we use having without group by then each table act as an individual Group. Which One is…
-1
votes
1 answer

Query two tables where one of them has been transposed

I have the following tables, USER and RECORDS. The USER table simply has the name of the user and the group they have access to. If a user has null as their group (such as BOB does), that means they are a super user and have access to all the…
user2924127
  • 6,034
  • 16
  • 78
  • 136
-1
votes
4 answers

SQL WHERE statement with multiple conditions

I have a movies, credits, people and roles table (below) I would like to find the names of the people who are both actors and directors. movies(TABLE) id int title credits(TABLE) id int movie_id int person_id int role_id int people(TABLE) id…
Lynn
  • 4,292
  • 5
  • 21
  • 44
-1
votes
4 answers

SQL query to display products that have been sold in one country and not another

Display the supplier names that have products sold to Mexico but not Spain SELECT s.CompanyName FROM OrderSupplier.Suppliers s WHERE Country <> 'Spain' (SELECT p.Id FROM OrderSupplier.Suppliers s JOIN OrderSupplier.Products p ON s.Id =…
user14152351
-1
votes
2 answers

Check if the number total appearance of the values in mysql database is odd in the table

I have a database with the user id, I want to check the total number of times each user id occurred and fetch only the ones which their total number of occurrence is odd in number. For example, I have "Sandra" with id 2 and appears 5 times, since 5…
-1
votes
1 answer

Check if Item has Data

I have a table that contains a whole lot of fields. What I am trying to do is see if any items are a missing certain fields. Example of data: +--------+----------+-------+ | ITEMNO | OPTFIELD | VALUE | +--------+----------+-------+ | 0 | x …
-1
votes
1 answer

count() function + derived table and Group - making it all work

Could someone please give me a hand in explaining in this example where the SUM function would go? I am trying to get a literal count on the number of returned columns, NOT the number of meta_key's for each post id. I want a number like there are 5…
Tim
  • 17
  • 6
-1
votes
1 answer

HAVING clause not filtering all conditions while using inner joins

Can anyone tell me why this statement is not limiting the results to today and the last 7 days? it is showing me results from 3 months ago along with results from today. In a different post I was told I had to change from a WHERE clause to a HAVING…
Tim
  • 17
  • 6