0

我在 sql developer 中使用 oracle 11i ..

这是我的查询:

SELECT itm.stu_no,wm_concat(uif.names) 
FROM personal uif,Coll itm, Dep ihts
WHERE uif.stu_id IN('26',    '29',    '32')   
  and (uif.stu_no,uif.stu_no) in 
  (
       select itm.stu_no,itm.stu_test_no 
       from Col itm,Dep ihts  
       where itm.stu_no = ihts.stu_no
       AND itm.status = 'A'
       AND ihts.status = 'A'
  )
  AND itm.status = 'A'
  and  itm.stu_no=ihts.stu_no and ihts.status = 'A'
  group by itm.stu_no;

内部查询(标记为强文本)返回...

stu_no             stu_test_no
-----------------------------------
123                 234

但完整的查询没有返回任何行。

这是预期的结果..

stu_no              wm_concat(names)
------------------------------------------
123                  James Alex
234                  (null)

有什么办法可以得到预期的结果?

4

1 回答 1

1

它不起作用,因为您要求两者uif.stu_no兼而有之: (123,123) 不在 ((123,234)) 和 (234,234) 不在 ((123,234))123 234


你可以试试这个:

SELECT itm.stu_no,wm_concat(uif.names) 
FROM personal uif,Coll itm, Dep ihts
WHERE uif.stu_id IN('26',    '29',    '32')   
  and uif.stu_no in 
  (
       select itm.stu_no 
       from Col itm,Dep ihts  
       where itm.stu_no = ihts.stu_no
       AND itm.status = 'A'
       AND ihts.status = 'A'
       union all
       select itm.stu_test_no 
       from Col itm,Dep ihts  
       where itm.stu_no = ihts.stu_no
       AND itm.status = 'A'
       AND ihts.status = 'A'
  )
  AND itm.status = 'A'
  and  itm.stu_no=ihts.stu_no and ihts.status = 'A'
  group by itm.stu_no;

但为什么不:

SELECT itm.stu_no,wm_concat(uif.names) 
FROM personal uif, Coll itm, Dep ihts
WHERE uif.stu_id IN('26',    '29',    '32')   
  and (uif.stu_no = itm.stu_no OR uif.stu_no = itm.stu_test_no)
  AND itm.status = 'A'
  and itm.stu_no = ihts.stu_no 
  and ihts.status = 'A'
  group by itm.stu_no;
于 2012-07-04T11:15:37.863 回答