1

我做了

创建表 tmp select min(xxx_id) from xxx group by y with count(*)>1;

现在我需要将此 tmp 表与另一个表连接起来,但是如何引用 tmp 表中唯一的列?

select * from table2 s, tmp t where s.xxx_id=t.xxx_id?

显然行不通,应该用什么替换 t.xxx_id?

4

2 回答 2

0

您需要将该列括在引号中,如下所示:

select * from table2 s, tmp t where s.xxx_id = t.`min(xxx_id)`;

但最好为列提供别名,因为它不会造成混淆:

create table tmp select min(xxx_id) AS min_xxx_id from xxx group by y having count(*)>1;
于 2012-08-07T11:07:43.147 回答
0

尝试这个:

select * 
from table2 s join tmp t  
on s.xxx_id=t.xxx_id
于 2012-08-07T11:11:20.880 回答