-1

データベースに対してこのクエリを実行すると、次のようになります。

コード:

SELECT TOP 20 
ha.datetime as ha_date, 
ha.id_hist_calls as ha_id_hist_calls, 
ha.name as ha_name, 
s.name as s_name, 
ss.name as ss_name 
FROM Hist_answer ha 
left join Hist_calls hc on hc.id_hist_calls = ha.id_hist_calls 
left join Service s on s.id_service = ha.from_id_service 
left join Service ss on ss.id_service = ha.id_service 

WHERE ha.id_hist_calls NOT IN ( 
SELECT 
ha.id_hist_calls as ha_id_hist_calls 
FROM Hist_answer ha 
WHERE ha.id_firm='39273' AND ha.datetime BETWEEN '2010.06.01 00:00:000' AND '2013.10.01 00:00:000' 
ORDER BY ha.datetime ASC 
) 

AND ha.id_firm='39273' 
AND ha.datetime BETWEEN '2010.06.01 00:00:000' AND '2013.10.01 00:00:000' 
ORDER BY ha.datetime ASC

次のエラーが表示されます。

Msg 1033, Level 15, State 1, Line 17
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

この選択クエリを修正するにはどうすればよいですか?

4

2 に答える 2