簡體   English   中英

編寫嵌套的 IIF 函數

[英]Write a nested IIF function

我遇到了這個問題

任務: 商業案例:

會計部門想知道在其帳戶上欠款的供應商的當前余額。 他們想將欠款超過 11,000 美元的供應商歸類為非常高的債務水平,將欠款在 11,000 美元至 500 美元之間的供應商歸類為高債務水平,將欠款在 500 美元至 200 美元之間的供應商歸類為中等債務水平以及其他任何人作為低債務級別。編寫一個返回 3 列的選擇語句:

  VendorName  BalanceDue: balance due calculated column using the SUM function  DebtLevel: nested IIF function that does the following: o Sum of Balances greater than $11,000 = 'Very High' o Sum of Balances between $11,000 and greater than $500 = 'High' o Sum of Balances between $500 and greater than $200 = 'Medium' o Sum of Balances equal to $200 or less = 'Low'

過濾結果以僅包括余額到期的供應商,並將結果從最大余額總和到最小余額排序。

嘗試這樣的事情:

SELECT VendorName
      ,SUM([balance]) AS [BalanceDue]
      ,IIF
        (
            SUM([balance]) => 11000
           ,'Very High debt level'
           ,IIF
           (
                SUM([balance]) >= 500 AND SUM([balance]) < 11000
               ,'High debt level'
               ,IIF
               (
                    SUM([balance]) < 500 AND SUM([balance]) <= 200
                    ,'Medium debt level'
                    ,'Low debt level'
               )
           )
        ) AS [DebtLevel]
FROM [my_table]
GROUP BY VendorName

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM