Results 1 to 2 of 2

Thread: Sort within Group

  1. #1

    Default Sort within Group

    Hi,

    I want to sort the set of records within each group.

    For ex : I'm sorting the records in ascending order by deptid & sorting the records within the group in decending order by empid (row 2 & 3). Also I want to select the first record of each group.

    DeptID, Name, EmpID
    1000, AAA, 100
    3000, BBB, 200
    500, CCC, 300
    1000, DDD, 50

    Expected output1 :

    DeptID, Name, EmpID
    500, CCC, 300
    1000, AAA, 100
    1000, DDD, 50
    3000, BBB, 200

    Expected output2 :

    DeptID, Name, EmpID
    500, CCC, 300
    1000, AAA, 100
    3000, BBB, 200

    Thanks,
    Arunn

  2. #2
    Lavastorm Employee gmullin's Avatar
    Join Date
    May 2014
    Location
    Chicago
    Posts
    185

    Default

    Give this a go.

    Code:
    node:Static_Data
    bretype:core::Static Data
    editor:sortkey=5cc7659774e23486
    output:@40fe6c55598828e5/=
    prop:StaticData=<<EOX
    DeptID,Name,EmpID
    1000,AAA,100
    3000,BBB,200
    500,CCC,300
    1000,DDD,50
    EOX
    editor:XY=210,160
    end:Static_Data
    
    node:Sort
    bretype:core::Sort
    editor:sortkey=5cc765aa505a356b
    input:@40fd2c743ebf4304/=Static_Data.40fe6c55598828e5
    output:@40fd2c746a2a3b47/=
    prop:CompareOrderExpr=<<EOX
    'DeptID'.long(),'EmpID'.long()
    EOX
    editor:XY=310,160
    end:Sort
    
    node:Agg_Ex
    bretype:core::Agg Ex
    editor:sortkey=5cc766184b08216e
    input:@4b4668c040aa5a85/=Sort.40fd2c746a2a3b47
    output:@4b4668e708143fb4/=
    prop:GroupBy=<<EOX
    'DeptID'.long()
    EOX
    prop:Script=<<EOX
    
    emit *
    where lastInGroup
    
    EOX
    prop:SortInput=false
    editor:XY=400,160
    node:Bypass
    bretype:::Bypass
    editor:shadow=4b467f7e02db3a85
    input:@4b467f7e129d45c1/=
    input:@4b467f830ffe047b/=
    output:@40fd2c7436717256/=
    end:Bypass
    
    node:Sort
    bretype:::Sort
    editor:shadow=4b467f8972dc33df
    input:@40fd2c743ebf4304/=
    output:@40fd2c746a2a3b47/=
    end:Sort
    
    node:Agg
    bretype:::Agg
    editor:shadow=4b467f9b3d5028c0
    input:@40fd2c7427456e5b/=
    output:@40fd2c744c862db0/=
    end:Agg
    
    end:Agg_Ex

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •