根据条件获取记录 [英] fetch the records based on the condition
本文介绍了根据条件获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含6个字段的表,其中一个字段名称为状态。
表包含10行。
状态字段由1到10的数据组成。
这里我需要根据状态获取数据(order by)价值,但价值可能会根据要求而变化。
例如,状态值为6的记录需要作为表格的第一行获取
我在谷歌尝试但无法得到它。
请帮帮我。
提前感谢。
Hi,
I have a table which consists of 6 fields with one field name as status.
table consists of 10 rows.
Status field consists of data from 1 to 10.
Here I need to fetch the data based(order by) on the status value, but value may be varied depending on the requirement.
For example, record with status value 6 need to be fetched as a first row of the table
I tried in google but couldn't get it.
Please help me on this.
thanks in advance.
推荐答案
试试这个:
Try this:
select * from tablename where status = 6
union
select * from tablename where status <> 6
您可以在查询中使用自定义排序条款。
例如
You can use a custom sort by clause in your query.
For example
SELECT Column1, Column2
FROM dbo.Country
ORDER BY CASE WHEN Status = 6 THEN 1
WHEN Status = 5 THEN 2
ELSE Status END ASC
For more detailed information please check this link[^].
Good luck,
OI
这篇关于根据条件获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文