从表

时间:2016-04-18 15:08:23

标签: sql

例如表1

transaction----------------Amount------------------date           

Premium billed              250                   20160202
Premium billed              150                   20160205
Premium billed              250                   20160202

表2

Reference no

001
002
003

我需要连接两个表并返回表2中具有重复项的参考号

注意:交易可以在我需要找到重复项的任何日期完成,因此日期未知。

这就是我的尝试:

SELECT refno, 
       a.movementdate 
FROM   lif_mgm_t_contract a WITH (nolock) 
WHERE  EXISTS (SELECT transactiontypeid, 
                      movementdate, 
                      movementcount, 
                      a.movementdate, 
                      refno 
               FROM   lif_tms_t_financialtransaction 
               WHERE  transactiongroupid = 1 
                      AND isbillingtrx = 1 
                      AND amount > 0 
                      AND a.movementdate = movementdate 
               GROUP  BY movementdate 
               HAVING Count (movementcount) > 1) 

0 个答案:

没有答案