0

我有一张这样的桌子

Days taken
12
10
10
12
9
10
8
10

我想要一个这样的查询

Type          | Count
Days over 10  |   2
Days under 10 |   6

到目前为止我有这个

SELECT Sum(IIf([table].[days taken]<=10,1,0)) AS [Days Under Ten], 
Sum(IIf([table].[days taken]>10,1,0)) AS [Days Over Ten]
FROM [table];

这给了我这个

Days under ten | Days over ten
6              |       2

但这不是我想要的,请帮助我。

4

1 回答 1

2

您当前的查询非常接近正确的版本。您将要使用:

SELECT 
  IIF([days taken] <=10, 'Days under 10', 'Days over 10') as Type,
  count([days taken]) as Total
FROM yourtable
group by IIF([days taken] <=10, 'Days under 10', 'Days over 10') 

您会看到我使用IIF来分配Days over 10Days under 10。然后你将把它添加IIFGROUP BYcount()

于 2013-03-05T17:17:20.853 回答