Skip to content
Advertisement

Select max value for each company in list, display longest value per company per day

I’ve looked at some of the other questions similar to this, but nothing I’ve found can quite get me there.

I have a table with multiple columns, but 3 of the columns are Company, Date, and WaitTime.

I want to select the longest WaitTime for each company and for each day. I’d like to display the results for the entire date range, showing each company and the longest wait time for that particular day.

Main Table

Desired Results

I can have many hundreds of interactions with each company, each day, so I am trying to find the longest wait time for each company for each day.

The most recent version I have tried is this;

However this isn’t quite showing me what I need.

Advertisement

Answer

You can use window functions. For your sample data, this would look like:

date is ambiguous (because there is a datatype that has the same name), so I renamed it to mydate. If that column actually has a time portion, then you need to remove it before ranking, like:

Note that rank() allows top ties, if any.

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