這是我的查詢:爲什麼我的查詢不起作用?
SELECT [MsgType],sr.ServiceName,content,COUNT(*) AS Occurrence
FROM [VSReceiveSend].[dbo].[ReceiveBuffer] rb
INNER JOIN dbo.Services sr ON rb.ServiceCode=sr.Code
where MsgType is not null and MsgType = 2
group by MsgType,CONTEnt, sr.ServiceName
order by COUNT(*) DESC
UNION
SELECT [MsgType],sr.ServiceName,content,COUNT(*) AS Occurrence
FROM [VSReceiveSend].[dbo].ReceivedSMS rb
INNER JOIN dbo.Services sr ON rb.ServiceCode=sr.Code
where MsgType is not null and MsgType = 2
group by MsgType,CONTEnt, sr.ServiceName
order by COUNT(*) DESC
SQL給我這個錯誤:Incorrect syntax near the keyword 'UNION'
!問題是什麼?
你想達到什麼目的?看起來像一個相當廣泛的查詢? – 2014-09-22 10:36:23
你在'UNION'關鍵字之前不能有'ORDER BY'子句 – 2014-09-22 10:36:56
@JohnWoo如何在這個查詢中使用UNION? – pejman 2014-09-22 10:48:04