SQl有条件地求和项

SQl有条件地求和项,sql,sql-server,sql-server-2008,ms-access,Sql,Sql Server,Sql Server 2008,Ms Access,我有下面的代码。如果是某项工作,则计数为1;如果是其他工作,则计数为0。我需要一种方法来计算0.5,如果它是第三个工作。我试过这个,它似乎总是算得上整数。有没有一种方法可以使用SQL实现这一点?我已经搜索过了,但找不到这样的方法来计算某些项目,例如0.5。这将有助于access数据库中的生产总量 SELECT TOP 1000 [Type of Work], COUNT(case when [Type of Work] IN ('LEP Decisions', 'Creditable C

我有下面的代码。如果是某项工作,则计数为1;如果是其他工作,则计数为0。我需要一种方法来计算0.5,如果它是第三个工作。我试过这个,它似乎总是算得上整数。有没有一种方法可以使用SQL实现这一点?我已经搜索过了,但找不到这样的方法来计算某些项目,例如0.5。这将有助于access数据库中的生产总量

SELECT TOP 1000 
 [Type of Work],
COUNT(case when  [Type of Work] IN 
('LEP Decisions',
'Creditable Coverage',
'Pends','Demographics',
'Consents','POA','PCP','Housing Verifications',
'LEP Cases') 
then 1 else Null END)as count
  ,[User ID]
FROM [Medicare_Enrollment].[dbo].[Sample]
group by [Type of Work], [User ID]

我建议将
COUNT
更改为
SUM
(从而将
1
0.5
0
相加,而不是将
Null
计算在内):


我建议将
COUNT
更改为
SUM
(从而将
1
0.5
0
相加,而不是将
Null
计算在内):


我相信COUNT也应该被SUMOh取代是的。我错了。我相信伯爵也应该被相扑取代。我的错误。
SELECT TOP 1000 
[Type of Work], 
SUM(case when  [Type of Work] IN ('LEP Decisions','Creditable Coverage','Pends','Demographics','Consents','POA','PCP','Housing Verifications','LEP Cases') then 1 
WHEN [Type of Work] IN ('') -- Put your work list
THEN 0.5
else 0 END)as count
,[User ID]
FROM [Medicare_Enrollment].[dbo].[Sample]
group by [Type of Work], [User ID]
  select top 1000 
         [Type of Work], 
         sum (case 
                when [Type of Work] in ('LEP Decisions','Creditable Coverage','Pends','Demographics','Consents','POA','PCP','Housing Verifications','LEP Cases') then 
                  1
                when [Type of Work] in ('SOME OTHER WORK', 'THIRD WORK') then
                  0.5  
                else 
                  0 -- nothing to add 
              end) as count,
         [User ID]
    from [Medicare_Enrollment].[dbo].[Sample]
group by [Type of Work], 
         [User ID]