我有以下在 SQL Server 中执行的 sql。我得到tx
表中行的乘积。tx
表中有 6 行,appt
表中没有匹配的行。master
表有一行包含个人信息,但是当我执行这个 sql 时,我得到 36 行而不是为每条记录获取一行。我得到了这个人的行数。我知道我在where
子句中需要另一个条件,但我没有尝试过:
SELECT "tx"."today",
"tx"."ada_no",
"tx"."tth_no",
"tx"."surface",
"tx"."billed",
"tx"."ins_pays",
"tx"."ins_pays1",
"tx"."balance1",
"tx"."dr_no",
"tx"."status",
"tx"."coma",
"tx"."comb",
"tx"."notes",
"tx"."appt",
"tx"."w_date",
"tx"."thekey",
"tx"."service",
"tx"."time",
"appt"."doa",
"master"."wip",
LEFT(ampm, 1) AS premed,
"master"."med_hx",
"tx"."comc",
"tx"."comd",
"tx"."i_bal2",
"tx"."ins_pays2",
"tx"."i_bal3",
"tx"."ins_pays3"
FROM "tx"
LEFT OUTER JOIN "appt"
ON "tx"."appt_key" = "appt"."appt_key",
"master"
LEFT OUTER JOIN "tx" tx1
ON "master"."master_key" = "tx1"."master_key"
WHERE "master"."master_key" = CAST(71563.00 AS NUMERIC(10, 2))
AND "master"."master_key" = "tx"."master_key"
ORDER BY "tx"."time" ASC,
"tx"."appt" ASC