sql-查找商店中最小产品的价格

cyvaqqii  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(389)

我想找出一家商店里最小产品的价格,另外,在另一列中,把这个价格填入同一家商店的所有产品中。以下是我的表格和“结果”列中所需的结果:
表1
这是我的要求,但它不填充价格: SELECT local ,product ,price ,IIF(MIN(Product) OVER (PARTITION BY Local)=Product,Price,NULL) as Results FROM Table1 谢谢

z0qdvdin

z0qdvdin1#

如果您想要最小产品的价格:

SELECT local, product, price, MAX(CASE WHEN product=MinProd THEN price ELSE 0 
  END) OVER (PARTITION BY Local)Results
    FROM
    (
    SELECT local, product, price, min(product) OVER (PARTITION BY Local) as 
    MinProd FROM Table1
    )
    X
gg0vcinb

gg0vcinb2#

你可以试试下面的-

SELECT local, product, price, min(price) OVER (PARTITION BY Local) as result
FROM Table1

相关问题