【发布时间】:2013-05-24 05:21:42
【问题描述】:
我有一个内部连接语句来获取在 3 个进程上运行并登录三个表的 id,
Select a.InquiryAccount ,a.InquiryAmount,a.InquiryCustName,a.InquiryLang, b.PayAmountPaid,b.PayScreenText,b.PayReceiptText, c.RevRefNo
from
inquiry a
inner join
Payment b
on a.InquiryAccount = b.PayAccount
inner join
Reversal c
on a.InquiryAccount = c.RevAccount
order by c.RevRefNo desc
它给出了我想要的结果,但是有些值翻了一番或重复,我想跟踪哪个帐户在内部连接结果上重复。
我尝试在我的内部连接上做这样的事情:
SELECT *
FROM Inquiry
WHERE InquiryAccount IN (
SELECT InquiryAccount
FROM Inquiry
GROUP BY InquiryAccount
HAVING (COUNT(InquiryAccount ) > 1)
)
显示唯一重复的帐户。
但是当我在Inner Join 上尝试group by 时出现错误,是否可以在inner join 上使用group by?或者在inner joinstatment 上发现重复值是否有任何解决方案?
这是我的内部连接语句的结果:
InquiryAccount InquiryAmount InquiryLang
10176601 124070 0
12344556 160050 1
10445654 160050 1
23456789 160050 1
22456666 160050 1
45324681 160050 1
14356890 160050 1
44566666 160050 1
22456666 160050 1
10176601 160050 1
这是我想从我的内部连接语句中生成的示例,它只会获得重复的帐户:
InquiryAccount InquiryAmount InquiryLang
10176601 124070 0
10176601 160050 1
22456666 160050 1
22456666 160050 1
【问题讨论】:
-
你能给出你想要的结果的样本记录吗?
-
@JW웃 我已经给了一个简单的记录
标签: sql-server duplicates inner-join