使用Union时,查询语句不可以使用Order by吗?(50分)

  • 主题发起人 主题发起人 proyer
  • 开始时间 开始时间
P

proyer

Unregistered / Unconfirmed
GUEST, unregistred user!
在SQL SERVER 2000中
有两个结构一致的查询,原使用Union 合并成一个查询集,成功。
但当查询使用order by时提示出错。
“在关键字 'union' 附近有语法错误。”
请高手指点。在线等待。
 
select * from (你那個沒有排序的正確的句子) order by 字段名
 
Select col1,col2,col3
from
(select col1,col2,col3 from table1 union select col1,col2,col3 from table2)
order by col2
 
order by 跟着第一个Select
 
我用的,通过

SELECT 接单操作员,CONVERT(CHAR(7),CAST(操作日期 AS SMALLDATETIME),20) AS 操作日期,SUM(接单数量) as 接单数量,sum(派单数量) as 派单数量,sum(返单数量) as 返单数量,sum(回访数量)as 回访数量 FROM
((SELECT 接单操作员,CAST(接单时间 AS INT) AS 操作日期, COUNT(*) as 接单数量,0 as 派单数量,0 as 返单数量,0 as 回访数量 FROM REC_INFO group by 接单操作员,CAST(接单时间 AS INT)) union
(SELECT 派单操作员,CAST(派单时间 AS INT),0,COUNT(*),0,0 from send_info group by 派单操作员,CAST(派单时间 AS INT)) union
(SELECT 返单操作员,CAST(返单日期 AS INT),0,0,COUNT(*),0 from ret_info group by 返单操作员,CAST(返单日期 AS INT)) union
(SELECT 回访操作员,CAST(回访时间 AS INT),0,0,0,COUNT(*) from response_info group by 回访操作员,CAST(回访时间 AS INT))) as t
WHERE 接单操作员 like '%' AND (操作日期 BETWEEN 30000 AND 40000) GROUP BY 接单操作员,CONVERT(CHAR(7),CAST(操作日期 AS SMALLDATETIME),20) ORDER BY 接单操作员,操作日期
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
875
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
934
DelphiTeacher的专栏
D
后退
顶部