我正在尝试运行以下查询,但出现此错误:
Msg 1033,第15级,状态1,第14行
除非还指定了TOP,OFFSET或FOR XML,否则ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效。
以下是查询:
WITH cbt_users AS
(
SELECT
mo, eid, rate, cat, quantity AS cbt_hours
FROM
crew.crew_rates
WHERE
rate_type = 'HOMSTUDY_HRS'
),
tot_hrs AS
(
SELECT
mo, eid, rate, quantity AS tot_hrs
FROM
crew.crew_rates
WHERE
rate_type = 'TOT HRS'
),
GU_cbt_compare AS
(
SELECT
cbt_users.mo, cbt_users.eid, cbt_users.rate, cbt_hours, tot_hrs,
CASE WHEN cbt_users.cat = 'REG' THEN 72 ELSE 75 END AS min_GU
FROM
cbt_users
LEFT JOIN
tot_hrs ON cbt_users.mo = tot_hrs.mo AND cbt_users.eid = tot_hrs.eid
ORDER BY
cbt_users.mo, cbt_users.eid
)
SELECT
mo, eid, rate, cbt_hours, tot_hrs, min_GU
FROM
GU_cbt_compare
ORDER BY
mo, eid