2008-12-12 7 views
14

मैं ओरेकल में एक प्रश्न जो does not बनाने के साथ समस्या हो रही है लापता मूल्योंओरेकल छोड़ दिया बाहरी नहीं दिखा रहा मिलती है सही शून्य मान

तालिका मेरे पास है पर शामिल करना चाहते हैं लगता है यह है:

table myTable(refnum, contid, type) 

values are: 
1, 10, 90000 
2, 20, 90000 
3, 30, 90000 
4, 20, 10000 
5, 30, 10000 
6, 10, 20000 
7, 20, 20000 
8, 30, 20000 

:

select a.refnum from myTable a where type = 90000 
select b.refnum from myTable b where type = 10000 and contid in (select contid from myTable where type = 90000) 
select c.refnum from myTable c where type = 20000 and contid in (select contid from myTable where type = 90000) 

क्वेरी मैं के बाद कर रहा हूँ के परिणाम यह है:

क्षेत्रों मैं के बाद कर रहा हूँ के नीचे एक ब्रेक यह है 210

a.refnum, b.refnum, c.refnum 

मैंने सोचा यह काम करेगा:

select a.refnum, b.refnum, c.refnum 
from myTable a 
left outer join myTable b on (a.contid = b.contid) 
left outer join myTable c on (a.contid = c.contid) 
where a.id_tp_cd = 90000 
and b.id_tp_cd = 10000 
and c.id_tp_cd = 20000 

तो मान होना चाहिए:

1, null, 6 
2, 4, 7 
3, 5, 8 

लेकिन इसके केवल लौटने:

2, 4, 7 
3, 5, 8 

मैं छोड़ दिया सोचा मिलती है सब दिखाई देंगे बाईं ओर मूल्य और दाईं ओर एक नल बनाएँ।

मदद :(

उत्तर

24

आपको लगता है कि बाईं कह में सही कर रहे हैं सही है, जहां कोई मिलान नहीं है के लिए nulls वापस आ जाएगी मिलती है, लेकिन आप अनुमति नहीं दे रहे हैं जब आप अपने जहां खंड के लिए इस शर्त जोड़ने के इन nulls वापस करने :

and b.id_tp_cd = 10000 
and c.id_tp_cd = 20000 

आप के बजाय शामिल होने, सही पर इतना ही प्रासंगिक पंक्तियों लौटा दिए जाते हैं खंड 'चालू'

select a.refnum, b.refnum, c.refnum 
from myTable a 
left outer join myTable b on (a.contid = b.contid and b.id_tp_cd = 10000) 
left outer join myTable c on (a.contid = c.contid and c.id_tp_cd = 20000) 
where a.id_tp_cd = 90000 
2

में इन डाल करने के लिए सक्षम होना चाहिए। या ansi

select a.refnum, b.refnum, c.refnum 
from myTable a, mytable b, mytable c 
where a.contid=b.contid(+) 
and a.contid=c.contid(+) 
and a.type = 90000 
and b.type(+) = 10000 
and c.type(+) = 20000; 


REFNUM  REFNUM  REFNUM 
---------- ---------- ---------- 
    1      6 
    2   4   7 
    3   5   8 
के बजाय ओरेकल वाक्यविन्यास का उपयोग करना
संबंधित मुद्दे