2

我继承了一些 ingres 数据库的东西。以前没用过ingres。我发现了以下查询来隔离不同的电子邮件地址记录。

select a.reg_uid as id, a.firstname, a.lastname, a.postzip_code, a.suburb, a.city, a.state, a.email, a.country 
from register a
inner join 
(
 select distinct email, min(reg_uid) as id from register 
  group by email 
) as b
on a.email = b.email 
and a.id = b.id

但是,当我将其插入 ingres 时,出现错误

"Table 'select' does not exist or is not owned by you."

有任何想法吗?

4

2 回答 2

1

如果您使用的是 Ingres 10S (10.1),那么您可以使用公用表表达式 (CTE),如下所示:

with b(email,id) as
(
 select distinct email, min(reg_uid) as id from register 
  group by email 
)
select a.reg_uid as id, a.firstname, a.lastname, a.postzip_code, a.suburb, a.city, a.state, a.email, a.country 
from register a
inner join b
on a.email = b.email 
and a.id = b.id

对于早期版本,您可以为 b 创建一个视图(CTE 实际上是一个内联视图)或将其重写为

select a.reg_uid as id, a.firstname, a.lastname, a.postzip_code, a.suburb, a.city, a.state, a.email, a.country 
from register a
where a.id = (
 select min(reg_uid) as id from register b
 where b.email=a.email
)
于 2013-10-23T11:04:40.623 回答
0

我在 Ingres 9 上成功地尝试了您的确切陈述:

create table register ( id char(10), reg_uid char(10), firstname char(10), lastname char(10), postzip_code char(10), suburb char(10), city char(10), state char(10), email char(10), country char(10) )

select a.reg_uid as id, a.firstname, a.lastname, a.postzip_code, a.suburb, a.city, a.state, a.email, a.country 
from register a
inner join 
(
 select distinct email, min(reg_uid) as id 
 from register 
  group by email 
) as b
on a.email = b.email 
and a.id = b.id
于 2014-08-19T13:23:47.980 回答