Skip to content
Advertisement

SQL Query for grouping within a segment with a condition

We need to select all the columns.

Condition: Within a single MAT+PLANT If any vendor crosses 80% we take records of that vendor only and reject other records within that MAT+PLANT. If within a single MAT+PLANT If all the vendors have below 80%, we consider all the records.

As shown in the image: Have attached input and output

image

Advertisement

Answer

You can use exists:

You can also use window functions:

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