2016-04-14 20 views
0

By Group ile çalışmadığı durumlarda:koşul bu SQL çalıştırdığınızda bir sorun var Toplaması

Create Table test_temp (
    gsid Number, 
    sl Number); 
Insert Into test_temp Values(53010100,15); 
Insert Into test_temp Values(53010000,10); 
Insert Into test_temp Values(53000000,5); 

Select * From (
Select Sum(sl), gsid, substr(gsid, 0, 4) sj_gsid, substr(gsid, 0, 2) pro_gsid 
From test_temp 
Group By Rollup(substr(gsid, 0, 2), substr(gsid, 0, 4), gsid)) 
Where sj_gsid <>'5300' 

Oracle 11g R2 (Linux).

Sanırım 5 satır iade edilecek.

what I wanted

Ama sonunda, ben 3 satır geri verilmesinde: Bunun gibi

wrong result

neler oluyor?

cevap

0

Kayıp olduğunuz iki satırın sj_gsid için NULL olduğu için yalnızca üç satır döndürüldü. NULL <> '5300' değerinin DOĞRU değil, UNKNOWN olduğunu ve yalnızca durumun DOĞRU olduğu satırların döndüğünü anlıyorsunuz, değil mi? Bunların dahil edilmesini istiyorsanız, or sj_gsid is null numaranızı where

+0

no'una eklemelisiniz. Daha dikkatli olmalıyım. Teşekkürler. – raphael