我正在尝试获取下面第一个查询中的所有数据,但下面第二个查询中的数据除外。
在这里,我第一次尝试使用with cte
and选择唯一数据/不同数据partition by
。
我尝试使用except,但出现此错误:
关键字“with”附近的语法不正确。如果此语句是公用表表达式、xmlnamespaces 子句或更改跟踪上下文子句,则前面的语句必须以分号结束。***
First query:
With cte as
(
select
*,
row_number() over (partition by [Employee ID] order by [QTR] DESC, Wk desc) rownumber
from
tbl_HC
)
select *
from cte
where rownumber = 1
and QTR = (Select max(QTR) from tbl_HC)
Except
--2nd query
With cte as
(
select
*,
row_number() over (partition by [Employee ID] order by [QTR] DESC, Wk desc) rownumber
from
tbl_HC
)
select *
from cte
where rownumber = 1
and Wk= (
Select max(Wk) from tbl_HC
where QTR = (Select max(QTR) from tbl_HC))`