menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Databases

>

Calculate ...
source image

Dev

1w

read

286

img
dot

Image Credit: Dev

Calculate a Pair of Minimum Values that Meet the Criteria within the Group — From SQL to SPL #12

  • A table stores events that occur for multiple accounts on multiple dates.
  • We need to find a pair of events that meet the criteria under each account: event a with the earliest date and event b with the earliest date among events that are more than 30 days away from event a.
  • In SQL, it involves multiple CTE clauses and is cumbersome to implement. In SPL, using grouping and sequence numbers, it becomes easier to select the first records within groups and the first record of the filtered result.
  • SPL Solution: Load data, group by account, select the first record from each group, filter out records more than 30 days away from the first record, select the first record again. Lastly, union the results for each group.

Read Full Article

like

17 Likes

For uninterrupted reading, download the app