MySQL查询来拉取项目,但始终在顶部显示特定的项目 [英] MySQL Query to pull items, but always show a certain one at the top

查看:58
本文介绍了MySQL查询来拉取项目,但始终在顶部显示特定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,在其中输入项目时,会给它们一个部分,例如书","dvds",海报",附件",衣服"等.因此,每个项目都有一个附加到其上的部分它.

I have a database where as items are entered in they're given a section such as "books", "dvds", "posters", "accessories", "clothing" etc. So each item has a section tacked onto it.

这是我用来查找唯一部分的SQL查询,因此我们可以使用它们按部分组织项目.

Here's the SQL query I'm using to find the unique sections so we can use them to organize the items by section.

SELECT DISTINCT section FROM merch

这给了我正确的结果,将唯一的部分放入了一个数组中.现在,我希望始终首先列出两个部分.因此,我一直都希望首先使用海报"和书籍",然后再显示其余类别.

That gives me the correct results, putting the unique sections into an array. Now, I'd like for two sections to always be listed first. So I always want "posters" and "books" first and second, then show the rest of the categories.

是否可以调整上面的查询,以便首先显示这两个部分,然后在下面显示其余的唯一类别?

Is there a way to adjust the above query so that those two sections are shown first, then the remaining unique categories show up below?

推荐答案

SELECT DISTINCT section FROM merch 
    ORDER BY FIELD(section, 'books', 'posters') DESC;

这篇关于MySQL查询来拉取项目,但始终在顶部显示特定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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