Finding values with same value on one field but distinct value on other field

时间:2015-07-31 19:21:27

标签: postgresql

Lets assume I have this postgresql table:

ProductStore

product_id store_id price

How do I query "which products hasn't the same price on every store".

I mean, same value on product_id but distinct value on price.

1 个答案:

答案 0 :(得分:1)

SELECT product_id
FROM "ProductStore"
GROUP BY product_id
HAVING COUNT(DISTINCT price) > 1