我有2张桌子
fct_collection
fct_collection_dr_details
我的目标是将它们组合起来,而不是像这样重复。
编辑
但我的输出就是这个
这是我的查询
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
答案 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