MySQL Forums
Forum List  »  Newbie

ways to use "Having"
Posted by: Francisco Pastrana
Date: February 16, 2016 11:27AM

Hi!

I'm getting stuck with something probably simple, but I have no idea how to investigate in google about this topic.

I have a table customers_logs


Id. (primary index)
Customer_id int (idx)
name varchar (150)
Date_of_operation date (idx)
type_of_operation smallint (idx)
amount decimal 14,0

I want to retrieve the customer_ids from the customers that operate in day first of january 2016 and have operations any other day between january 02 to 31, excluding all the customes that only have operations in day first and not in any other day.


I was thinking of something like this but with no success:

SELECT customer_id, name, sum(amount) AS amount
FROM customers_logs
WHERE date_of_operation = '2016-01-01'
GROUP BY customer_id
HAVING date_of_operation BETWEEN '2016-01-02' AND '2016-01-31'


I appreciate any help, Thanks!

Options: ReplyQuote


Subject
Written By
Posted
ways to use "Having"
February 16, 2016 11:27AM
February 16, 2016 01:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.