且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用算术表达式创建列的 sql 查询

更新时间:2023-02-10 19:20:49

一种方法是将整个现有查询放入 CTE,然后您可以从中选择并执行计算.

One way would just be to chuck your entire existing query into a CTE then you can select from that and perform the calculations.

;WITH CTE
     AS (
        /*Paste your existing query*/
        )
SELECT *,
       Sum_SalesStores / Sum_Products AS Foo,
       Sum_SalesStores / Sum_Stores   AS Bar
FROM   CTE
ORDER  BY Foo,
          Bar