仅当左侧表的grp_id_num介于右侧表的beg_group和end_group之间时,我才尝试匹配这两个表
+-------------+--+
| grp_id_num |
+-------------+--+
| XA0001 |
+-------------+--+
+---------------------------+---------------------------+-----------------------
| detail_lookup.beg_group | detail_lookup.end_group | detail_lookup.agent
+---------------------------+---------------------------+-----------------------+
| XA0000 | XZ9999 | Exchange |
| WW9988 | WW9988 | DEVINE ETHIER |
| P00001 | P99999 | SHOP |
| 002359 | 002359 | LG |
我的选择查询:
select a.grp_id_num,b.beg_group,b.end_group,b.fundtype from
(select codesetkey as grp_id_num from codedetail limit 10)a
left outer join
detail_lookup b
on(a.grp_id_num >= b.beg_group and a.grp_id_num <= b.end_group)
错误:
Error: Error while compiling statement: FAILED: SemanticException [Error 10017]: Line 5:3 Both left and right aliases encountered in JOIN 'beg_group' (state=42000,code=10017)
预期结果:
XA0001 , XA0000 ,XZ9999,Exchange
有人可以帮助我配置单元1.1吗?
答案 0 :(得分:0)
配置单元仅支持等值连接,
您可以尝试以下查询吗?
WITH res1 AS
(
SELECT codesetkey AS grp_id_num
FROM codedetail
ORDER BY codesetkey limit 10 -- adding order by to get the first set of 10 records
), res2 AS
(
SELECT a.grp_id_num,
b.beg_group,
b.end_group,
b.fundtype
FROM res1 a,
codedetail b
WHERE a.grp_id_num >= b.beg_group
AND a.grp_id_num <= b.end_group)
SELECT codesetkey,
NULL,
,
NULL,
NULL
FROM res1
LEFT OUTER JOIN res2
ON res1.codesetkey=res2.grp_id_num
WHERE res2.grp_id_num IS NULL
UNION
SELECT *
FROM res2