在sql server中我们是不能再union查询中直接使用order by 进行排序的,因此我们必须使用一些比较巧妙的方法来得到我们想要的结果。

sqlStr = "select * from ("; 
sqlStr += "select NodeID,NodeName from Case_Tree where RootType=2 and NodeType=2"; 
sqlStr += " union all "; 
sqlStr += "select ActionID,ActionName from Case_Action where ActionCategory = 'Function'"; 
sqlStr += ") as T order by NodeName";

结果如下图所示:

[唐胡璐] - SQL UNION All 排序问题

 

相关文章:

  • 2021-11-13
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2021-11-29
  • 2021-12-22
猜你喜欢
  • 2021-07-23
  • 2021-08-14
  • 2021-09-13
  • 2021-12-29
  • 2021-05-23
  • 2021-05-18
相关资源
相似解决方案