Quote (Dtrain3083 @ Jan 12 2016 08:40am)
Well in that same query I'm pulling in about 15 other metrics, which have vastly different criteria, so I need it in the select statement.
I guess my follow up question to that is , is it possible to add in some criteria in the select statement as a workaround?
setting the date trunc to equal one another unfortunately doesn't capture the cases where the closed date falls into the month after.
so if i understand correctly, you want to see the two rows (from your example) and just have the top one with a 0 count? perhaps you can show your sample output.
suppose your data looks like this:
Quote
Customer ID Email_Date, Closed_Date
123, 2015-05-01, 2015-06-04
123, 2015-06-01, 2015-06-04
123, 2015-06-01, 2015-06-05
123, 2015-06-02, 2015-06-04
what is your desired output?
1) 0 for each row not within 30 days, 1 otherwise. this can be accomplished with the case statement; no count required
Quote
Customer ID Email_Date, Closed_Date, count
123, 2015-05-01, 2015-06-04, 0
123, 2015-06-01, 2015-06-04, 1
123, 2015-06-01, 2015-06-05, 1
123, 2015-06-02, 2015-06-04, 1
2) you said "most recent email_date":
Quote
Customer ID max(Email_Date), Closed_Date, count
123, 2015-05-01, 2015-06-04, 0
123, 2015-06-01, 2015-06-05, 1
123, 2015-06-02, 2015-06-04, 2
or something else? keep in mind if you wanna see less than 4 rows, you'll need something in the where or a group by, as i suggested earlier. if you wanna see all 4 rows, you'll have to clarify what the count represents.
This post was edited by carteblanche on Jan 12 2016 10:51pm