我以前問過如何通過MYSQL連接多個表,但現在我遇到了一個新問題。mysql innerjoin和union
說我有這幾個表。通過晶體報告
報銷表
-Name---Check Number-----Date------Reimbursement--
-John-----1--------------7/23/12-------$100-------
-Joe------2--------------7/23/12-------$102-------
-Jane-----3--------------7/23/12-------$103-------
-Jill-----4--------------7/23/12-------$104-------
原始權利要求
-Name---Check Number-----Date---------Amount--
-John-----1--------------7/23/12-------$100---
-Joe------2--------------7/23/12-------$102---
-Jane-----3--------------7/23/12-------$103---
-Jill-----4--------------7/23/12-------$100---
調整權利要求
-Name---Check Number-----Date---------Amount--
-Jill-----4--------------7/23/12-------$4-----
最終結果應當是
-Name---Check #---Claim Type----Date Paid----Amount----Reimbursement--
-John-----1-------Original--------7/23/12-----$100-------$100---------
-Joe------2-------Original--------7/23/12-----$102-------$102---------
-Jane-----3-------Original--------7/23/12-----$103-------$103---------
-Jill-----4-------Original-------7/23/12------$100-------$104---------
-Jill-----4-------Adjusted-------7/23/12------$4----------------------
不
-Name---Check #---Claim Type----Date Paid----Amount----Reimbursement--
-John-----1-------Original--------7/23/12-----$100-------$100---------
-Joe------2-------Original--------7/23/12-----$102-------$102---------
-Jane-----3-------Original--------7/23/12-----$103-------$103---------
-Jill-----4-------Original-------7/23/12------$100-------$104---------
-Jill-----4-------Adjusted-------7/23/12------$4---------$104---------
我目前的腳本是:
Select mt.`Check Number` as `Check Number`,
mt.`Payment Date` as `Payment Date`,
mt.`Payment Type` as `Payment Type`,
c1.`Facility Name` as `Facility Name`,
'Adjustment June 2012' as `Claim Type`,
c1.`Amount` as Amount,
mt.Reimbursement as Reimbursement
From Reimbursement mt
Inner Join ClaimAdjust_6_2012 c1
on c1.`Check Number` = mt.`Check Number` and
mt.`Payment Date` = c1.`Payment Date`
Where mt.`Payment Date`>='2012-7-1' And
mt.`Payment Date`<'2012-8-1'
Union
Select mt.`Check Number` as `Check Number`,
mt.`Payment Date` as `Payment Date`,
mt.`Payment Type` as `Payment Type`,
c1.`Facility Name` as `Facility Name`,
'Original June 2012' as `Claim Type`,
c1.`Amount` as Amount,
mt.Reimbursement as Reimbursement
From Reimbursement mt
Inner Join Claim_6_2012 c1
on c1.`Check Number` = mt.`Check Number` and
mt.`Payment Date` = c1.`Payment Date`
Where mt.`Payment Date`>='2012-7-1' And
mt.`Payment Date`<'2012-8-1'
有什麼問題嗎? – RedFilter 2012-07-23 16:06:08
如何在Crystal報表上創建最終結果,而不必爲相同支票號碼兩次報銷 – user1489261 2012-07-23 16:07:53