当前位置: 代码迷 >> Sql Server >> 看看这种需求 只用sql如何解决
  详细解决方案

看看这种需求 只用sql如何解决

热度:60   发布时间:2016-04-27 20:28:29.0
看看这种需求 只用sql怎么解决?
利用SQL查询出 所要的字段数据后
然后 要将其中的一个字段或者两个 必需排第一或者 一 二 位.
该怎么解决?????

------解决方案--------------------
如果你说的是那种行转列的动态生成列名的话,可以在生成 SQL语句的时候使用order by
select @[email protected]+Field1 from table1 order by Field
如果有必要的话 可以 在order by 里面用CASE
select @[email protected]+Field1 from table1 order by (case Field when 'test1 ' then 0 when 'text2 ' then 2 else Field end)
  相关解决方案