查找具有相同商品编号的每行行的最低价格输入的详细信息 [英] Find details for minimum price entry for each group of rows with the same article number

查看:112
本文介绍了查找具有相同商品编号的每行行的最低价格输入的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多关于这个的书,但是没有一个对我有用.有人可以帮忙吗?

I read a lot about this, but none worked for me. Can someone help?

我有一张大桌子,上面放着很多不同的文章(很多都用相同的EAN),并且总是只需要最便宜的文章(按价格排序)并带有正确的AN:

I have a big table with a lot of different articles (a lot with same EAN) and need always only the cheapest one (sort by price) with the correct AN:

*art   price   an    ean
*Test |79,00|15770|0808736558136
*Test |85,00|k3238|0808736558136
*Test |68,00|r4850|0808736558136
*Test |65,00|a1117|0808736558136
*Test |78,00|t8619|0808736558136

期待这个:

*Test |65,00|a1117|0808736558136

推荐答案

SELECT B.*
  FROM BigTable AS B -- Why do SQL questions omit the table names so often?
  JOIN (SELECT EAN, MIN(Price) AS Price
          FROM BigTable
         GROUP BY EAN
       ) AS P
    ON B.EAN = P.EAN AND B.Price = P.Price
 ORDER BY B.EAN;

子查询查找每个EAN的最低价格;外部查询查找与EAN和该EAN的最低价格相匹配的详细信息.如果对于给定的EAN,有两个记录具有相同的最低价格,则将同时选择这两个记录.

The sub-query finds the minimum price for each EAN; the outer query finds the details that match the EAN and minimum price for that EAN. If there are two records with the same minimum price for a given EAN, both will be chosen.

这篇关于查找具有相同商品编号的每行行的最低价格输入的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆