没有重复的

时间:2017-10-12 08:16:22

标签: mysql sql

我有2张桌子

fct_collection

enter image description here

fct_collection_dr_details

enter image description here

我的目标是将它们组合起来,而不是像这样重复。

enter image description here

编辑

enter image description here

但我的输出就是这个

enter image description here

这是我的查询

SELECT a.appkey,
       a.drnumber,
       a.amt,
       b.prnumber,
       b.prdate
FROM fct_collection_dr_details AS a
INNER JOIN
    (SELECT MAX(appkey) AS 'appkey',
            MAX(prnumber) AS 'prnumber',
            prdate
     FROM fct_collection
     GROUP BY prdate) AS b ON a.appkey = b.appkey

我曾经appkey

加入他们

这是表格

fct_collection

         appkey             prnumber    prdate
10/04/2017 15:49:2032s1gXox 1234567   2017-10-04
10/05/2017 14:29:142qmvYRJM 2356489   2017-10-05

fct_collection_dr_details

    appkey                 drnumber   amt
10/04/2017 15:49:2032s1gXox 12345     2500
10/05/2017 14:29:142qmvYRJM 234569    5000
10/05/2017 14:29:142qmvYRJM 698745    10000

1 个答案:

答案 0 :(得分:0)

尝试左连接

SELECT a.appkey, a.drnumber, a.amt, b.prnumber, b.prdate 
FROM fct_collection_dr_details AS a 
left JOIN 
(SELECT MAX(appkey) AS 'appkey', MAX(prnumber) AS 'prnumber', prdate 
FROM fct_collection GROUP BY prdate) AS b ON a.appkey = b.appkey