Skip to content
Advertisement

getting first sunday using the window function

I need to get the first Sunday from each month and add that as a new column to the original table. The below query works only when the first row of a group starts with Sunday i.e for March month. It doesn’t work when the month is not starting with Sunday.

Query:

Incorrect result

How can this be solved using window function?

Advertisement

Answer

I would suggest:

This is a lot like your logic, but it uses min() instead of first().

Actually, your table doesn’t seem to have a year column — and you really want the year included in the partition by. So if one really isn’t available, then:

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