Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created May 26, 2021 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elyphas/9d729450efedaae5d71229ef090e487d to your computer and use it in GitHub Desktop.
Save elyphas/9d729450efedaae5d71229ef090e487d to your computer and use it in GitHub Desktop.
val qryOutputs = aqlu"""
FOR item IN tblrecipe_details
LET item_por_pieza = (
FOR i IN tbl_claves_por_pieza FILTER i.cve_articulo == item.key_item RETURN i
)
FOR itemPre IN ( LENGTH(item_por_pieza) > 0 ? item_por_pieza: [ { /* no match exists*/ } ] )
LET recipesFechas = (
FOR r IN tblrecipe
FILTER r.fiscal_period == item.fiscal_period &&
r.folio == item.folio &&
r.type_document == item.type_document
RETURN r.date2
)
FOR recipeFech IN ( LENGTH ( recipesFechas ) > 0 ? recipesFechas: [ { /* no match exists*/ } ] )
COLLECT
fecha = recipeFech,
cve_articulo = item.key_item,
descripcion = item.description_item,
presentacion = itemPre.presentacion
AGGREGATE
output = SUM(item.supplied)
SORT fecha, cve_articulo, output DESC
RETURN {
fecha,
cve_articulo,
descripcion,
output,
presentacion,
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment