MySQL Forums
Forum List  »  Oracle

sum(case when max(date) then 1 else 0 end)
Posted by: Hal Campbell
Date: September 15, 2012 07:43AM

I am new to MySQL so I thank you in advance for your help.

I have a subscription table that contains subscriptions for a user. Each user could have multiple rows indicating their subscription history. Each rows in the subscription table contain "Date Created"=created_date and "Expiration Date" = exp_date.

I need to calculate the total number of rows where created_date is within a date range and number of rows that contains exp_Date within a date range.

For exp_date I need to check the oldest or MAX exp_date.

Here is what I've tried but using Max within the case doesn't work.



Select
SUM(Case when created_date between 'yyyy-mm-dd' and 'yyyy-mm-dd' then 1 else 0 end) as Created_Count
sum(case when max(Exp_Date between 'yyyy-mm-dd' and 'yyyy-mm-dd' then 1 else 0 end) as Exp_Count

Options: ReplyQuote


Subject
Views
Written By
Posted
sum(case when max(date) then 1 else 0 end)
6705
September 15, 2012 07:43AM


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.