当前位置: 代码迷 >> Sql Server >> 两个表时间字段名不同,union后的order by该怎样写?解决方法
  详细解决方案

两个表时间字段名不同,union后的order by该怎样写?解决方法

热度:9   发布时间:2016-04-27 16:07:30.0
两个表时间字段名不同,union后的order by该怎样写?
SELECT     title,   times   FROM     item1     WHERE   title   LIKE   '% "   +   Replace(Recordset1__MMColParam,   " ' ",   " ' ' ")   +   "% '         Union   all   (SELECT     title,   addtimes   as   times   FROM   item2     WHERE   title   LIKE   '% "   +   Replace(Recordset1__MMColParam,   " ' ",   " ' ' ")   +   "% '   order   by   ....写times?addtimes?怎么写?

------解决方案--------------------
select * from
(
SELECT title, times FROM item1 WHERE title LIKE '% " + Replace(Recordset1__MMColParam, " ' ", " ' ' ") + "% '
Union all
(SELECT title, addtimes as times FROM item2 WHERE title LIKE '% " + Replace(Recordset1__MMColParam, " ' ", " ' ' ") + "% '
) t
order by times

  相关解决方案