min_by.sql 637 B

123456789101112131415161718192021
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. $t = AsList(
  4. AsStruct(1 as key, 200 as value),
  5. AsStruct(2 as key, 100 as value)
  6. );
  7. $f = AGGREGATION_FACTORY("minby");
  8. select Yql::Aggregate($t, AsTuple(), AsTuple(AsTuple(AsAtom("res"),
  9. $f(ListItemType(TypeOf($t)), ($z)->{ return AsTuple($z.value, $z.key) }))));
  10. $f = AGGREGATION_FACTORY("minby", 10);
  11. select Yql::Aggregate($t, AsTuple(), AsTuple(AsTuple(AsAtom("res"),
  12. $f(ListItemType(TypeOf($t)), ($z)->{ return AsTuple($z.value, $z.key) }))));
  13. use plato;
  14. insert into @a select AsTuple(value, key) as vk from as_table($t);
  15. commit;
  16. select AGGREGATE_BY(vk, $f) from @a;