SQL查询删除重复项

时间:2015-06-10 12:48:36

标签: sql

使用GoldMine CRM编写此查询,尝试根据记录类型,潜在客户创建日期和上次联系日期查找系统中的人员。现在,在运行查询时,它会显示多个结果,对于John Smith来说,它向我显示了他所有的信息,而不仅仅是我想要的最后一个联系日期。我将在下面粘贴查询任何帮助将非常感激。

SELECT DISTINCT CONTACT1.CONTACT    AS Contact_Name, 
                Min(CONTACT1.CONTACT), 
                CONTACT1.KEY1       AS Rec_Type, 
                CONTACT1.CREATEON   AS Lead_Type, 
                CONTHIST.LASTDATE   AS Last_Contact, 
                CONTHIST.RESULTCODE AS Stamp 
FROM   CONTACT1 
       INNER JOIN CONTHIST 
               ON CONTACT1.ACCOUNTNO = CONTHIST.ACCOUNTNO 
WHERE  CONTACT1.KEY1 = 'Lead' 
GROUP  BY CONTACT1.CONTACT, 
          CONTACT1.KEY1, 
          CONTACT1.CREATEON, 
          CONTHIST.LASTDATE, 
          CONTHIST.RESULTCODE 
HAVING Count(CONTACT1.CONTACT) = 1 
ORDER  BY CONTACT1.CREATEON 

0 个答案:

没有答案