答案 0 :(得分:0)
如果您正在寻找组合两个查询,CTE和其他查询。然后你可以这样做:
WITH CTE
AS
(
SELECT *,
Rn = ROW_NUMBER() OVER(PARTITION BY productCode ORDER BY productId)
FROM sellingprice
), CTE2
AS
( -- you can put here the second query you need to combine with the first cte
SELECT
sp.productid, sp.productname, ...
from sellingPrice sp
inner join cost ...
)
-- here the two queries are accessible from cte, cte2
SELECT *,
productcode = CASE
WHEN Rn = 0 THEN productCode
ELSE productCode+ CHAR(65 + Rn -1)
END, .... -- you can select other columns
from CTE c1
INNER JOIN CTE2 c2 ON c1.productid = c2.productid