开发者

How to rewrite query using CTE

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜