---
title: "根据in中顺序在查询结果中排序"
author: "cy913417"
date: "2012-07-17T14:49:40Z"
tags: []
categories: ["数据库"]
slug: "in"
draft: false
lastmod: "2012-07-17T14:49:40Z"
id: 1596378
url: "https://it456.iteye.com/blog/1596378"
---

在数据查询的时候 xx.id in(3,5,1，9,7 ) 结果一般都会按 1,3,5,7,9进行排序，有些时候我们却需要按3,5,1,9,7 这样的顺序进行数据返回。

 

此时只需要在 对结果order by 时 加上

 

order by charindex(','+rtrim(id)+',', ',3,5,1,9,7,') 即可