使用 SQL Server 2012 .... 此代码作为独立脚本工作,但我需要在iif(...)
嵌套在 a中返回的值Case...when
作为更大脚本的一部分:
with GroupedValues (Value, Frequency, SelectingCriteria) AS
(Select
Table1.Cost as Value,
Count(*) as Frequency,
Table2.AccountNumber as SelectingCriteria
from Table1, Table 2
)
Group by Table1.Cost, Table2.AccountNumber)
Select
Max(Value) as Value
From GroupedValues a INNER JOIN
(select Max(Frequency) AS MaxFrequency
from GroupedValues) b
on a.Frequency=b.MaxFrequency