按特定字段值排序SQL查询 [英] Ordering SQL query by specific field values

查看:280
本文介绍了按特定字段值排序SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL查询(使用Firebird作为RDBMS),在该查询中,我需要按字段EDITION版本对结果进行排序.但是,我需要按字段的内容排序.即"NE"排在第一位,"OE"排在第二位,"OP"排在第三位,空白排在最后.不幸的是,我不知道如何实现这一目标.我曾经做过的只是ORDER BY [FIELD] ASC/DESC而已.

I've got a sql query (using Firebird as the RDBMS) in which I need to order the results by a field, EDITION. I need to order by the contents of the field, however. i.e. "NE" goes first, "OE" goes second, "OP" goes third, and blanks go last. Unfortunately, I don't have a clue how this could be accomplished. All I've ever done is ORDER BY [FIELD] ASC/DESC and nothing else.

有什么建议吗?

我真的应该澄清:我只是希望在这里学习更多.我现在有了它,只有多个select语句定义了要首先显示的语句.查询是相当大的,我真的希望学习可能更有效的方法: 示例:

I really should clarify: I was just hoping to learn more here. I have it now that I just have multiple select statements defining which to show first. The query is rather large and I was really hoping to learn possibly a more effecient way of doing this: example:

SELECT * FROM RETAIL WHERE MTITLE LIKE 'somethi%' AND EDITION='NE'
UNION 
SELECT * FROM RETAIL WHERE MTITLE LIKE 'somethi%' AND EDITION='OE'
UNION
SELECT * FROM RETAIL WHERE MTITLE LIKE 'somethi%' AND EDITION='OP'
UNION (etc...)

推荐答案

Order By Case Edition
    When 'NE' Then 1
    When 'OE' Then 2
    When 'OP' Then 3
    Else 4 End 

这篇关于按特定字段值排序SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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