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

SQL Syntax - having clause?

I should know this - but I don't, can anyone help me with a syntax plz. Let's say I'm tracking runners in a cross-country relay race, I've got a main join table that associated runners with races... and a runners table that tells me where/when they…
j-p
  • 3,698
  • 9
  • 50
  • 93
-1
votes
1 answer

SQL: Syntax Error after Having (Select ...) table

The question is to extract information about customer that spent the most (in total over their lifetime as a customer) total_amt_usd, and COUNT the web_events they had for each channel. I am trying to create an extra table from original table, and…
Ivy
  • 1
-1
votes
2 answers

Find users who have visited URL A and B with SQL?

Let's say you have a table with user, url, datetime, in which each row is a website visit. How to find users who have visited both an URL contaning string pattern A and visited an URL containing string pattern B? The fact it's "containing a string…
Basj
  • 41,386
  • 99
  • 383
  • 673
-1
votes
2 answers

Display the MAX record with JOIN

I want to select the highest transaction amount and the corresponding Album Name to that amount. This is what I have so far: SELECT a.AlbumName, MAX(t.TransAmt) AS HighestSale FROM TRANSACTIONS t JOIN COLLECTIONS c ON c.CollectionID =…
nathan
  • 3
  • 1
-1
votes
4 answers

How does this NOT IN in a Having statement in Oracle work

I'm trying to rewrite an old Oracle SQL query I inherited and there is one part I don't understand. My new version comes up with about a dozen extra records and I've concluded it's because the HAVING clause in the original version is filtering them…
jackstraw22
  • 517
  • 10
  • 30
-1
votes
3 answers

Select field where a column has more than n elements SQL

look this: Given the table "Customer" that has the following columns: • Name1  First name of the customer. • Name2  Second Name of the customer. • Surname1  Customer's First Surname. • Surname2  Second Surname of the client. • T_Documento  Type…
R.Ramirez
  • 31
  • 5
-1
votes
1 answer

SQL How to select rows based on values from multiple rows

Hi I ran into a problem regarding the following tables CREATE TABLE BOOKS ( Title varchar(255), Year INT, Type ENUM("Horror", "Fantasy"), Pages INT, PRIMARY KEY (Title, Year) ); …
-1
votes
1 answer

Select with multiple conditions from a single user

I want to do a search of all the users who have taken the same exams as me in a database (MySql). The structure of the database is id, user_id, exam_id and date Well, I have done the exams with the id 5,8,9, I want to know how many have done the…
-1
votes
3 answers

Find the students who attended at least one exam but not the Max nor the Min score

My solution passed the first test case, but got the wrong answer after final submission. I am thankful for anyone willing to point out my mistakes. Thanks! The question is as below: Table: Student +---------------------+---------+ | Column Name …
Chen
  • 383
  • 2
  • 12
-1
votes
1 answer

How to calculate the average of a column in mySQL grouped by another column in a conditional statement?

I need to calculate the average of one column where a second column has the same values. For example, you have Col1 | Col2 a | 2 a | 9 b | 6 b | 10 I need to retrieve the average of Col2 grouped by Col1, so (9+2)/2 and (6+10)/2. I am…
Becca
  • 59
  • 1
  • 4
-1
votes
2 answers

sql query to get customers who only used trips for only for airports

Trips Customer_id src_id dest_id c1 1 2 c1 2 1 c2 1 2 c2 2 3 Location id name 1 Airports 2 Movies 3 Market Is there any other good way than using…
harshini
  • 77
  • 3
  • 7
-1
votes
2 answers

SQL Query: Get those orders that have products greater than 1

psa_psofk is order ID and psa_prdfk is product ID. I want only those orders that have more than one product i.e I don't want order 1 and 5.
artsnr
  • 952
  • 1
  • 10
  • 27
-1
votes
1 answer

Only use first of multiple matches SQL

I need to find the sum of credits from click_stats where source = 'reward' for all users who have claimed at least one of the 3 promo codes AND have the total clicks displayed. Tables: +---------------------------------------------+ | click_stats …
Jason
  • 25
  • 4
-1
votes
2 answers

Pulling Unique Products Bought by One Customer Compared to Another

I have been asked to display a list of products purchased by customers in Germany that were not purchased by customer in the US. After trying to conceptualize how I would structure this, I seemed to have hit a road block. I wrote a query to provide…
-1
votes
3 answers

how to count all rows are approved in sql?

I have this line data, where it also shows the status: approved, in progress, not yet started. I need to count how many lines are ALL APROVED based on the line colors. the data is similar to this: line color status 1 red not yet…
nomnomyang
  • 65
  • 1
  • 6