日期:2014-05-16  浏览次数:20808 次

再求一句SQL
这样一个表
ID   Name
---------
1     A1
2     A2
3     A3
4     A2
5     A4
6     A6
7     A1
8     A2
9     A4

我想返回   Name字段值是   "A1 ",   "A2 ",   "A3 "的记录的数量
现在我是分三次做的
SELECT   COUNT(*)   FROM   Table   WHERE   Name= "A1 "
SELECT   COUNT(*)   FROM   Table   WHERE   Name= "A2 "
SELECT   COUNT(*)   FROM   Table   WHERE   Name= "A3 "

现在我想一句SQL,只查询一次就返回,能实现吗?

------解决方案--------------------

Select
SUM(IIF(Name = 'A1 ', 1, 0)) As A1Count,
SUM(IIF(Name = 'A2 ', 1, 0)) As A2Count,
SUM(IIF(Name = 'A3 ', 1, 0)) As A3Count
From
TEST1