2016-10-17 35 views
0

我不確定這是否可能,但我試圖在從同一列(已經工作)中劃分兩個值之後過濾「結果」。劃分同一列中的兩個值,然後只顯示0到3之間的值

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之間的值。

感謝很多提前

+1

哪些DBMS您使用的? –

回答

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

這工作完美。謝謝 – Kastriot

2

試試這個

SELECT * 
FROM (

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

這一個現在確實爲我工作,也許我做錯了,但它給出了一個錯誤,「運行率」是無效的列。 – Kastriot

+0

您是否嘗試過與上述完全相同:剛剛更新了RunRate與[[Run Rate]] –

+0

是的,我嘗試了確切的格式,只不過列使用「」代碼(Zoho Reports)編寫。 – Kastriot

相關問題