2016-10-13 4 views
0

Ich habe den folgenden Code. Es zählt 1, wenn es bestimmte Arbeit ist und 0, wenn es andere Arbeit ist. Ich brauche eine Möglichkeit, 0,5 zu zählen, wenn es eine dritte Arbeit ist. Ich habe das versucht und es scheint immer in ganzen Zahlen zu zählen. Gibt es eine Möglichkeit, dies mit SQL zu tun? Ich habe gesucht und kann eine solche Methode nicht finden, um einige Elemente als 0.5 zu berechnen. Das wird mit der Produktion Summen in einer Access-Datenbank helfenSQL Summe Artikel bedingt

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] 

Antwort

1

Ich schlage vor Wechsel COUNT-SUM (und damit zusammenfassend 1, 0.5 oder 0 - anstelle des Zählens Null):

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] 
+0

gearbeitet danke ich wusste, dass ich etwas verpasst habe – lance9877

1
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] 
+0

Ich glaube, COUNT sollte auch ersetzt werden durch SUM –

+0

Oh yeah. Mein Fehler. – Esty