SELECT ARRAY_AGG(material.id) AS id,
ARRAY_AGG(material.materialCode) AS bpc,
ARRAY_AGG(material.size) AS size,
ARRAY_AGG(material.oldMaterialNumber) AS pattern,
ARRAY_AGG(material.country) AS country,
ARRAY_AGG(priceData.price) AS wsp,
SUM(TO_NUMBER(stockData.totalStock)) AS totalStock
FROM bridgestone_test material
JOIN bridgestone_test stockData
ON KEYS material.stockId
JOIN bridgestone_test priceData
ON KEYS material.pricePrio3Id
WHERE material.docType = "MATERIAL"
GROUP BY material.size, material.oldMaterialNumber, material.country
Hi @jrn ,
Try this . If needed use TO_STR(d.totalStock) AS totalStock
SELECT d.size, d.pattern, d.country, d.totalStock, u.*
FROM (SELECT material.size,
material.oldMaterialNumber AS pattern,
material.country,
SUM(TO_NUMBER(stockData.totalStock)) AS totalStock,
ARRAY_AGG( DISTINCT {material.id, "wsp": priceData.price, "bpc":material.materialCode}) AS arr
FROM bridgestone_test AS material
JOIN bridgestone_test AS stockData ON KEYS material.stockId
JOIN bridgestone_test AS priceData ON KEYS material.pricePrio3Id
WHERE material.docType = "MATERIAL"
GROUP BY material.size, material.oldMaterialNumber, material.country) AS d
UNNEST d.arr AS u;
Is material.stockId, material.pricePrio3Id is ARRAY or single value?
In that case you can also try this. It works like LEFT JOIN i.e. if no stock/price document also it gives material document
SELECT d.size, d.pattern, d.country, d.totalStock, u.*
FROM (SELECT material.size,
material.oldMaterialNumber AS pattern,
material.country,
SUM(TO_NUMBER(totalStock)) AS totalStock,
ARRAY_AGG( DISTINCT {material.id, wsp, "bpc":material.materialCode}) AS arr
FROM bridgestone_test AS material
LET totalStock = (SELECT RAW stockData.totalStock FROM bridgestone_test AS stockData USE KEYS material.stockId)[0],
wsp = (SELECT RAW priceData.price FROM bridgestone_test AS priceData USE KEYS material.pricePrio3Id)[0]
WHERE material.docType = "MATERIAL"
GROUP BY material.size, material.oldMaterialNumber, material.country) AS d
UNNEST d.arr AS u;
hi @vsr1 , i was just curious what can be the minimum execution time this query can get? right now at 5k records it’s taking up 5 to 6 secs with index. thank you.
It is hard to tell 5 to 6 sec might be long for 5k documents. If you are using EE
execute query in query work bench and goto Plan Text Tab and take look (This post has links how to analyze Filter taking too long - #4 by Marco_Greco)