Skip to content
Advertisement

Return number of rows since last occurrence

I want to find the number of reports a user has submitted since a user last received a personalized response. The column response_type has 3 possible values: “No Response,” “Templated Response,” and “Personalized Response”

I wrote a query that has the most recent cases at the top.

I would like to count the number of reports since the last response_type = “Personalized Response” and return the date of the last “Personalized Response”enter image description here

Advertisement

Answer

I want to find the number of reports a user has submitted since a user last received a personalized response.

You can use ROW_NUMBER() to assign a rank to each record by descending date within contact groups, and then check the row number of the last record having the concerned response, like:

To filter on a given contact, you can simply add a WHERE clause to the inner (or outer) query. If you really need this LIKE condition on the contact:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement