我正在使用 mySQL。我有一张根据我们的 sku 每天更新的表格。 SKU 具有重复值,因为存在与其关联的定价层。我需要创建一个 View ,该 View 将显示所有行,但仅显示 1 个 sku 及其下方的关联 sku 行,以便我可以每天导出以在 magento 中进行更新。 Magento 不允许在导入过程中出现重复的 sku。这是一个例子:
sku _tier_price_qty _tier_price_price 013964223286 10 1 50 1 100 1 9332153001025 5 1 25 1 50 1 9332153001032 5 1 25 1 50 1 9332153001063 5 1 25 1 50 1 9332153001049 5 1 25 1 50 1 640420002569 5 1 25 1 50 1 640420002538 5 1 25 1 50 1 640420002521 5 1 25 1 50 1
最佳答案
尽管这种类型的格式可能更适合在报告应用程序中处理,但此查询应该执行您想要的操作:
select
case when x.tier_qty is not null then t.sku else null end tier_qty,
t.tier_qty,
t.tier_price
from t
left join (
select sku, min(tier_qty) tier_qty
from t
group by sku
) x on t.sku = x.sku and t.tier_qty = x.tier_qty
order by t.sku, t.tier_qty;
关于mySQL View 显示不同的值及其下面的所有相关行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31642828/