• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ
blackhero 2004年12月25日
昨天加order by 的问题
select top 1000 * from VIEW_ALMEVT0409 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' ) and plcname='大钟寺' union select top 1000 * from VIEW_ALMEVT0410 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' ) and plcname='大钟寺' union select top 1000 * from VIEW_ALMEVT0411 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' ) and plcname='大钟寺'


我问我的view_almevt0409,view_almevt0410,view_almevt0411表是动态生成的,(有时就一个view_almevt0409表,有时有6个表).怎么加order by 呀
//参考
加上排序order by 以后为
select t1.a,t2.a,t3.a from (select top 1000 * from VIEW_ALMEVT0409 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' order by ) and plcname='大钟寺') t1,(select top 1000 * from VIEW_ALMEVT0410 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' ) and plcname='大钟寺' order by) t2,(select top 1000 * from VIEW_ALMEVT0411 where (evtdate>='2004-09-24' and evtdate<='2004-12-24' order by) and plcname='大钟寺'
) t3
//////////////////////////////////////////////////////
SELECT t1.*, t2.*, t3.*
FROM (SELECT TOP 1000 *
FROM VIEW_ALMEVT0409
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t1 CROSS JOIN
(SELECT TOP 1000 *
FROM VIEW_ALMEVT0410
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t2 CROSS JOIN
(SELECT TOP 1000 *
FROM VIEW_ALMEVT0411
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t3
////////////////////////////////////////////////////
SELECT t1.*, t2.*, t3.*
FROM (SELECT TOP 1000 *
FROM VIEW_ALMEVT0409
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t1,
(SELECT TOP 1000 *
FROM VIEW_ALMEVT0410
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t2,
(SELECT TOP 1000 *
FROM VIEW_ALMEVT0411
WHERE (evtdate = '2004-09-24' AND evtdate = '2004-12-24') AND
plcname = '大钟寺'
ORDER BY AlmID) t3
...全文
47 点赞 收藏 4
写回复
4 条回复

还没有回复,快来抢沙发~

发动态
发帖子
.NET技术社区
创建于2007-09-28

4.8w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告