0

I have view at postgres db from this query

SELECT order_product.order_id,
  array_agg(order_product.product_id) AS itemset 
FROM order_product
GROUP BY order_product.order_id
ORDER BY order_product.order_id;

and this is the structure look like:

enter image description here

And the question is, how can U filter data at (itemset) just show where the value is more than 1 (example: don't show = {8}, just show the value when containing 2 data or more like this = {8,10})

1 Answer 1

1

Use the having() clause:

SELECT op.order_id,
       array_agg(op.product_id) AS itemset 
FROM order_product op
GROUP BY op.order_id
HAVING count(*) > 1 --<< here
ORDER BY op.order_id;
Sign up to request clarification or add additional context in comments.

1 Comment

thank you that solved my problem, very grateful for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.