2017-03-08 7 views
0

によって順番は私が日付でテーブルを注文したいと思いますが、私のクエリがエラーが表示されます。SQL:日付

The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.

マイクエリ:私はIntervalDateで注文することができますどのように

select intervaldate, [M1], [M2], [M3], [M4], [M5], [M6], [M7], [M8] 
    from 
    (select intervaldate,amount, name from (Select tSystem.Name, IntervalCount.IntervalDate, 
    sum(case when CounterName = 'Prod' then calculationUnits else 0 end) as Amount from IntervalCount, tsystem where 

    IntervalCount.intervaldate between '2017-03-06 00:00:00.000' and '2017-03-08 00:00:00.000' and IntervalCount.systemid =tsystem.id 

    group by tSystem.Name, IntervalCount.Intervaldate 
order by IntervalCount.Intervaldate asc 
    ) as T3) as T1 
    pivot 
    (sum (amount) 
    for name in ([M1], [M2], [M3], [M4], [M5], [M6], [M7], [M8]) 

    ) as t2 

+2

次のようにクエリの最後にorder byを交換する必要がありますか? –

答えて

3

メッセージエラーは、(あなたのケースでは)派生テーブルのを使用できないと述べています。 あなたは、DBMSは、使用している

select intervaldate, [M1], [M2], [M3], [M4], [M5], [M6], [M7], [M8] 
    from 
    (select intervaldate,amount, name from (Select tSystem.Name, IntervalCount.IntervalDate, 
    sum(case when CounterName = 'Prod' then Units else 0 end) as Amount from IntervalCount, tsystem where 

    IntervalCount.intervaldate between '2017-03-06 00:00:00.000' and '2017-03-08 00:00:00.000' and IntervalCount.systemid =tsystem.id 

    group by tSystem.Name, IntervalCount.Intervaldate 
order by IntervalCount.Intervaldate asc 
    ) as T3) as T1 
    pivot 
    (sum (amount) 
    for name in ([M1], [M2], [M3], [M4], [M5], [M6], [M7], [M8]) 

    ) as t2 
    order by Intervaldate asc