Mysql:从表中提取

发布于 2024-12-10 17:30:26 字数 583 浏览 0 评论 0原文

我在组合查询时遇到一些问题。我需要显示按顺序拉出的图像,如果它们位于“编辑”部分,那么如果它们有要在其中显示的顺序,将首先显示编辑图像,但如果它没有在该部分中排序,它将默认并拉出已订购的常规图像(可能不是编辑类型图像,但如果没有其他可用的图像,则为首选图像)。我现在所拥有的是下面的查询,但它不会首先拉出编辑排名的图像,而是“ordered_by”似乎优先。

SELECT i.img_name, a.artist_path_name, a.artist_dir, a.artist_name, ck.catKey_id        
FROM images AS i JOIN artists AS a USING (artist_id)
JOIN img_cat_table AS imc USING ( img_id )
JOIN catkeys AS ck USING (catKey_id)
WHERE site = 'editorial' AND editorial_order = 1 OR ordered_by = 1 GROUP BY artist_name ORDER BY ed_banner

这可能是我错过的一些愚蠢的东西——任何和所有的帮助都是值得赞赏的。

I am having some trouble putting a query together. I need to show images pulled in the order of if they are in the "editorial" section then if they have an order to be displayed in it will show the editorial image first but if its not ordered in that section it would just default and pull the regular image that is ordered already (which may not be a editorial type image but is a preferred one if nothing else is available). What I have now is the query below BUT that doesn't pull the editorial ranked images first but rather the "ordered_by' seems to take precedence.

SELECT i.img_name, a.artist_path_name, a.artist_dir, a.artist_name, ck.catKey_id        
FROM images AS i JOIN artists AS a USING (artist_id)
JOIN img_cat_table AS imc USING ( img_id )
JOIN catkeys AS ck USING (catKey_id)
WHERE site = 'editorial' AND editorial_order = 1 OR ordered_by = 1 GROUP BY artist_name ORDER BY ed_banner

Its probably something silly that I am missing -- any and all help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟花肆意 2024-12-17 17:30:26

尝试类似的方法:

...
ORDER BY CASE WHEN site = 'editorial' AND editorial_order = 1 THEN 1 ELSE 2 END,
         ed_banner

Try something like:

...
ORDER BY CASE WHEN site = 'editorial' AND editorial_order = 1 THEN 1 ELSE 2 END,
         ed_banner
没企图 2024-12-17 17:30:26

或者以更简单的方式实现相同的想法

ORDER BY (site = 'editorial' AND editorial_order = 1) DESC, ed_banner

它只是利用 FALSE、TRUE 的顺序。

您应该从 WHERE 子句中删除相应的条件。

or the same idea in a simpler way

ORDER BY (site = 'editorial' AND editorial_order = 1) DESC, ed_banner

It simply utilizes the order of FALSE, TRUE.

You should remove the respective conditions from the WHERE clause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文