我有两张table。表一包括所有的指标。表二包括所有条款。
我试图从metric表中得到扩展了品牌、优先级和具有最低优先级的相应商品的国家代码的所有行。
SELECT national_code, brand, width, height, inch, `load`, speed, season, rof, MIN(`prio`) as prio FROM `whitelistarticles`
WHERE prio < 1000
GROUP BY
width, height, inch, `load`, speed,season,rof;
SELECT metrics.*, articles.national_code, articles.prio, articles.brand FROM whitelistmetrics as metrics
LEFT JOIN (SELECT national_code, brand, width, height, inch, `load`, speed, season, rof, MIN(`prio`) as prio FROM `whitelistarticles`
WHERE prio < 1000
GROUP BY
width, height, inch, `load`, speed,season,rof) as articles on
metrics.width = articles.width AND
metrics.height = articles.height AND
metrics.inch = articles.inch AND
metrics.load = articles.load AND
metrics.speed = articles.speed AND
metrics.season = articles.season AND
metrics.rof = articles.rof
WHERE articles.prio IS NOT NULL
ORDER BY width, height, inch, `load`, speed;
问题是这个查询给了我一个组的最低优先级,但没有给优先级为的行。它最终给了我错误的品牌和错误的国家代码,而它选择了集团的最低优先级。
例如。两篇文章具有相应的度量,一篇文章的优先级为20,另一篇文章的优先级为15。我要这篇文章的品牌和国家代码,优先权是15。它最后给了我15个优先权,国家代码和文章的品牌名称优先权是20。
如何修复此查询,使其连接优先级最低的行,而不是仅连接优先级最低的行?
1条答案
按热度按时间lo8azlld1#
这对你有帮助