問題這是我的腳本:與聯合許多表讓許多價值
select c.rendering_id as prov_number, c.begin_date_of_service as date_of_service,
c.practice_id as group_number, v.enc_nbr as invoice, p.person_nbr as patient,
v.enc_nbr as invoice_number, c.charge_id as transaction_number,
t.med_rec_nbr as primary_mrn, p.last_name, p.first_name,
z.payer_id as orig_fsc_number, z.payer_id as curr_fsc_number,
c.location_id as location_number, c.closing_date as posting_date,
c.quantity as service_units, c.amt as charge_amount,
c.cpt4_code_id as procedure_code, r.description as procedure_name,
x.tran_code_id as pay_code_number, ISNULL([modifier_1],'') as modifier_code_1,
ISNULL([modifier_2],'') as modifier_code_2, ISNULL([modifier_3],'') as modifier_code_3,
ISNULL ([icd9cm_code_id],'') as dx_code_1, ISNULL ([icd9cm_code_id_2],'') as dx_code_2,
ISNULL ([icd9cm_code_id_3],'') as dx_code_3, ISNULL ([icd9cm_code_id_4],'') as dx_code_4
from charges c, person p, patient t, patient_encounter v, encounter_payer z, cpt4_code_mstr r, transactions x
where c.person_id = p.person_id
and c.person_id = t.person_id
and c.person_id = v.person_id
and c.person_id = z.person_id
and c.cpt4_code_id = r.cpt4_code_id
and c.person_id = x.person_id
and c.practice_id = '0001'
and c.closing_date >= GetDate() - 7
我應該得到大約14K行,但這個我得到一對夫婦十萬。我覺得應該有一個內部連接來糾正它,但我已閱讀了一堆帖子,似乎可以得到它的工作。它是迄今爲止我在SQL中做過的最大的一次拉。
任何幫助將大大幫助。
其實,你已經在上面的查詢中使用了內連接。 – biziclop 2012-07-26 19:39:07
左連接只能給他*更多*結果行。 – wildplasser 2012-07-26 19:39:53
您需要確定哪些表具有多對一的關係並添加更多條件來過濾數據。 – ShaneBlake 2012-07-26 19:41:24