SQL服务器:超过两个表用于合并功能
SQL Server: more than two tables for coalesce function
我需要帮助,我设法成功查询了两个 table,但是当我尝试执行两个以上 table 时出现错误。请帮我。
这是SQL:
select
coalesce(a.LOT_ID, b.LOT_ID,c.LOT_ID,d.LOT_ID) as LotId,
coalesce(a.CheckIn, b.CheckIn,c.CheckIn, d.CheckIn) as CheckIn,
coalesce(a.CheckOut, b.CheckOut,c.CheckOut, d.CheckOut) as CheckOut,
coalesce(a.StatusDesc, b.StatusDesc,c.StatusDesc, .StatusDesc) as StatusDesc
from
LOT_LOC_BOND a, LOT_LOC_IEBT b,LOT_LOC_MBT c,LOT_LOC_SEAL d
where
a.LOT_ID = b.LOT_ID,
AND c.LOT_ID = d.LOT_ID
错误指出
Incorrect syntax near ','.
末尾缺少别名
coalesce(a.StatusDesc, b.StatusDesc,c.StatusDesc, .StatusDesc) --d is missing
开始使用 INNER JOIN
语法连接表
SELECT COALESCE(nullif(a.LOT_ID,''), nullif(b.LOT_ID,''), nullif(c.LOT_ID,''), nullif(d.LOT_ID,'')) AS LotId,
COALESCE(a.CheckIn, b.CheckIn, c.CheckIn, d.CheckIn) AS CheckIn,
COALESCE(a.CheckOut, b.CheckOut, c.CheckOut, d.CheckOut) AS CheckOut,
COALESCE(a.StatusDesc, b.StatusDesc, c.StatusDesc, d.StatusDesc) AS StatusDesc --missing alias name d
FROM LOT_LOC_BOND a
INNER JOIN LOT_LOC_IEBT b
ON a.LOT_ID = b.LOT_ID
INNER JOIN LOT_LOC_MBT c
ON a.LOT_ID = c.LOT_ID
INNER JOIN LOT_LOC_SEAL d
ON c.LOT_ID = d.LOT_ID
我需要帮助,我设法成功查询了两个 table,但是当我尝试执行两个以上 table 时出现错误。请帮我。
这是SQL:
select
coalesce(a.LOT_ID, b.LOT_ID,c.LOT_ID,d.LOT_ID) as LotId,
coalesce(a.CheckIn, b.CheckIn,c.CheckIn, d.CheckIn) as CheckIn,
coalesce(a.CheckOut, b.CheckOut,c.CheckOut, d.CheckOut) as CheckOut,
coalesce(a.StatusDesc, b.StatusDesc,c.StatusDesc, .StatusDesc) as StatusDesc
from
LOT_LOC_BOND a, LOT_LOC_IEBT b,LOT_LOC_MBT c,LOT_LOC_SEAL d
where
a.LOT_ID = b.LOT_ID,
AND c.LOT_ID = d.LOT_ID
错误指出
Incorrect syntax near ','.
末尾缺少别名
coalesce(a.StatusDesc, b.StatusDesc,c.StatusDesc, .StatusDesc) --d is missing
开始使用 INNER JOIN
语法连接表
SELECT COALESCE(nullif(a.LOT_ID,''), nullif(b.LOT_ID,''), nullif(c.LOT_ID,''), nullif(d.LOT_ID,'')) AS LotId,
COALESCE(a.CheckIn, b.CheckIn, c.CheckIn, d.CheckIn) AS CheckIn,
COALESCE(a.CheckOut, b.CheckOut, c.CheckOut, d.CheckOut) AS CheckOut,
COALESCE(a.StatusDesc, b.StatusDesc, c.StatusDesc, d.StatusDesc) AS StatusDesc --missing alias name d
FROM LOT_LOC_BOND a
INNER JOIN LOT_LOC_IEBT b
ON a.LOT_ID = b.LOT_ID
INNER JOIN LOT_LOC_MBT c
ON a.LOT_ID = c.LOT_ID
INNER JOIN LOT_LOC_SEAL d
ON c.LOT_ID = d.LOT_ID