开发者

How to rewrite query using CTE

开发者 https://www.devze.com 2022-12-12 11:45 出处:网络
I have query like this DECLARE @A INT SET @A = 22 SELECTMoo, 1st - 2nd + 100 AS WWW FROM( SELECT1 + Num AS Moo,

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

精彩评论

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

关注公众号