3

我需要修改我的查询以添加其他联接。但是新的联接可能需要是左联接。我不确定该怎么做。我正在使用 Informix:

     set    query   "SELECT DISTINCT x.xfertype,x.app_type,x.service_type,x.lang,x.area_type,x.area_value,x.module,x.field1,x.field2,x.disabled,a.frames,a.allocs,a.term_id,t.term,c.center_id,c.center_name,a.message_id,x.field3,x.apn_type,x.global, a.icm, s.group_name "
    append  query   " FROM test_xfertypes AS x, test_allocation AS a, test_terms AS t, test_callcenter AS c"
    append  query   " AND a.xfertype = x.xfertype "
    append  query   " AND a.term_id = t.term_id "
    append  query   " AND t.center_id = c.center_id ";

test_xfertypes AS x包含area_value(整数)

我想用另一个新表加入上面的表test_routing_groups AS s

我想离开加入让它返回s.group_name WHERE x.area_value IN (s.area_id);如果 group_name 存在,则返回 group_name,否则返回 null。

4

1 回答 1

3

您需要为此使用标准连接语法。您的查询应如下所示:

SELECT DISTINCT x.xfertype, x.app_type, x.service_type, x.lang,x.area_type,
       x.area_value, x.module, x.field1, x.field2, x.disabled,
       a.frames, a.allocs, a.term_id,
       t.term,c.center_id, c.center_name,a.message_id, x.field3, x.apn_type,x.global,
       a.icm, s.group_name
FROM test_xfertypes x join
     test_allocation a
     on a.xfertype = x.xfertype join
     test_terms t
     on a.term_id = t.term_id join
     test_callcenter c
     on t.center_id = c.center_id

您只需添加以下内容即可离开加入另一个表:

left outer join test_routing_groups s
on x.area_value IN (s.area_id)

您还可以使用“x.area_value = s.area_id”而不是“in”子句。

于 2012-06-27T17:59:11.797 回答