Skip to content
Advertisement

window functions and grouping – how to propagate data from row 1 through row 3 in a partition?

I have this query below:

And here’s the result set from running this query: enter image description here

Here’s what I’m having trouble with. What I want to do is for when there’s a grouping as defined by the partition, I want to put as the EmailTo field the Email Address for the top record of the group (row 1):

enter image description here

When there’s no grouping, just use the Email Address for the EmailTo field. What’s the best way to go about this?

Advertisement

Answer

You could use first_value() over the relevant partition.

e.g., Assuming you mean the same partition as used for row_number, add the following line after your row_number line

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