我们可以使用 ORDER BY
CTE 表达式中的子句?
;with y as
(
select
txn_Date_Time, txn_time, card_No, batch_No, terminal_ID
from
C1_Transaction_Information
where
txn_Date_Time = '2017-10-31'
order by
card_No
)
select * from y;
错误信息:
Msg 1033, Level 15, State 1, Line 14
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.Msg 102, Level 15, State 1, Line 25
Incorrect syntax near ','.
最佳答案
您不能在 CTE 中使用“Order By”,但您可以将 order by 移动到调用 CTE 的 select 语句并产生我相信您正在寻找的影响
;with y as(
select txn_Date_Time,txn_time,card_No,batch_No,terminal_ID
from C1_Transaction_Information
where txn_Date_Time='2017-10-31'
)
select * from y order by card_No;
关于sql - CTE 表达式中的 TSQL-ORDER BY 子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47171039/