How to reuse calculated columns avoiding duplicating the sql statement?

后端 未结 6 1359
忘掉有多难
忘掉有多难 2020-12-09 07:51

I have a lots of calculated columns and they keep repeting themselves, one inside of the others, including nested cases statements.

There is a really simplified ver

6条回答
  •  心在旅途
    2020-12-09 08:51

    Another option if someone is still interested:

    with aa(a) as ( select 1+2 ) 
    , bb(b) as ( select a+3 from aa ) 
    ,cc(c) as ( select b*7 from bb) 
    SELECT aa.a, bb.b, cc.c 
    from aa,bb,cc
    

提交回复
热议问题