1

不幸的是,在我职业生涯的大部分时间里,我都使用了一个名为 4th dimension 的古怪的法国数据库。它的行为与 MySQL 非常不同。因此,请耐心等待可能是一个非常简单的问题。

我有如下查询:

SELECT c.id, p.last_name, e.full_name, l.Current_step, l.Current_Step_date,  
FROM customer as c, lesson as l , Employee as e 
WHERE l.Prospect_ID =c.id
AND c.ID_ofProducer= e.id  
AND last_name = 'Smith' 

我正在取回 3 条记录。但它们都是一样的。

ID      Last_name     Full_name     Current_Step      Current_Step_date
61245   Smith         Jim Jones     Registered        2013-04-14
61245   Smith         Jim Jones     Registered        2013-04-14
61245   Smith         Jim Jones     Registered        2013-04-14

我确实希望61245 Smith回来。

但; 没想到回响了3次。

有人能解释一下我到底做错了什么/我应该做些什么吗?

4

2 回答 2

1

我认为您可以使用GROUP BY聚合函数。

SELECT c.id, p.last_name, e.full_name, l.Current_step, l.Current_Step_date,  
FROM customer as c, lesson as l , Employee as e 
WHERE l.Prospect_ID =c.id
AND c.ID_ofProducer= e.id  
AND last_name = 'Smith'   
GROUP BY c.id
于 2013-05-30T19:57:41.533 回答
1

在其他领域可能存在差异。要查看它们,这应该有效:

SELECT * 
FROM customer as c, lesson as l , Employee as e 
WHERE l.Prospect_ID =c.id
AND c.ID_ofProducer= e.id  
AND last_name = 'Smith' 

如果没有差异,则一个或多个表中有重复项。

如果要消除此类重复项,可以使用以下distinct关键字:

SELECT distinct c.id, p.last_name, e.full_name, l.Current_step, l.Current_Step_date
FROM customer as c, lesson as l , Employee as e 
WHERE l.Prospect_ID =c.id
AND c.ID_ofProducer= e.id  
AND last_name = 'Smith' 

如果不支持,您可以使用以下方法执行相同的操作group by

SELECT c.id, p.last_name, e.full_name, l.Current_step, l.Current_Step_date
FROM customer as c, lesson as l , Employee as e 
WHERE l.Prospect_ID =c.id
AND c.ID_ofProducer= e.id  
AND last_name = 'Smith' 
group by c.id, p.last_name, e.full_name, l.Current_step, l.Current_Step_date
于 2013-05-30T20:00:24.793 回答