我先尝试了。
Create table tablec (
id string,
group int,
rownumber int);
insert into table c
select * from (select distinct a.id,a.group,a.rownumber from
table a join table b
on a.group = b.group where a.rownumber <= b.rownumber ) T;
我也尝试了以下查询并获得相同的结果。
insert into table c
select * from (select a.id, a.group, a.rownumber from
table a , table b
where a.group = b.group and a.rownumber <= b.rownumber ) T;
运行查询时我不会遇到错误。它正在创建表C,但值不限。谁能暗示我为什么会发生?
示例屏幕截图
我认为您不必使用JOIN
和DISTINCT
。这样的相关exists
查询应该很好。首先,查看它是否仅给您所需的记录。然后使用此选择。
Insert
语句。
SELECT a.group_id
,a.group_name
,a.rownumber
FROM tablea a
WHERE EXISTS (
SELECT 1
FROM tableb b
WHERE a.group_id = b.group_id
AND a.rownumber <= b.rownumber
);
demo