SELECT COUNT(Sonuc)
,CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden
FROM Kayit_MPI_Kontrolu
GROUP BY
CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden
我有一个查询。 我想进入Sonuc列OK和NOK值计数。我该怎么办?
答案 0 :(得分:1)
select sum( case when Sonuc = 'OK' then 1 else 0 end ) as countOK,
sum( case when Sonuc = 'NOK' then 1 else 0 end ) as countNOK,
,CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden
FROM Kayit_MPI_Kontrolu
GROUP BY
CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden
答案 1 :(得分:0)
就像这样,
SELECT SUM(CASE WHEN Sonuc = 'OK' THEN 1 ELSE 0 END) AS OK
,SUM(CASE WHEN Sonuc = 'NOK' THEN 1 ELSE 0 END) AS NOK
,CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden
FROM Kayit_MPI_Kontrolu
GROUP BY
CAST(Tarih AS Date)
,VardiyaAdi
,ReferansNo
,MusteriAdi
,KontrolEden