将相同列中的两个值分开,然后仅显示0到3之间的值

时间:2016-10-17 10:07:45

标签: sql

我不确定这是否可行,但我试图在从同一列(已经有效)分割两个值后过滤“结果”。

SELECT
  "Business Name",
  (sum(CASE
       WHEN "Source Indicator" = 'Month end cash balance'
         THEN "EUR AMOUNT"
       END) / sum(CASE
                  WHEN "Source Indicator" = 'Total OPEX'
                    THEN "EUR AMOUNT"
                  END)) AS "Run Rate"
FROM "Steering_database_eur"
WHERE MONTH("End Date") = (MONTH(GETDATE()) - 1)
GROUP BY "Business Name"

现在我只需要在“运行速率”列中仅显示介于-10和3之间的值。

提前多多感谢

2 个答案:

答案 0 :(得分:2)

试试这个

SELECT * 
FROM (

        --your query here
)t
WHERE [Run Rate] BETWEEN 0 AND 3

答案 1 :(得分:1)

不确定这是否属于您的目标:

SELECT
         "Business Name",
         (sum(case
                 when "Source Indicator"  = 'Month end cash balance' then "EUR AMOUNT"
             end) / sum(case
                 when "Source Indicator"  = 'Total OPEX' then "EUR AMOUNT"
             end)) as "Run Rate"
FROM  "Steering_database_eur" 
WHERE    MONTH("End Date")  = (MONTH(GETDATE()) -1)
GROUP BY  "Business Name" 
HAVING  (sum(case
                 when "Source Indicator"  = 'Month end cash balance' then "EUR AMOUNT"
             end) / sum(case
                 when "Source Indicator"  = 'Total OPEX' then "EUR AMOUNT"
             end)) BETWEEN 0 AND 3