I have query like this
DECLARE @A INT
SET @A = 22
SELECT Moo, 1st - 2nd + 100 AS WWW
FROM (
SELECT 1 + Num AS Moo,
((@A-100)*开发者_如何学运维3)+num AS 1st,
((@A-100)*4)+num AS 2nd
FROM tblC
WHERE ColA = 'Atic' AND Num < 7
) AS TTT
How to use CTE to rewrite same query?
WITH TTT AS (
SELECT 1+Num as Moo,
((@A-100)*3)+num as [1st],
((@A-100)*4)+num as [2nd]
FROM tblC
WHERE ColA = 'Atic' and Num < 7)
SELECT Moo, [1st]-[2nd]+100 AS WWW
FROM TTT;
精彩评论