我正在尝试在Microsoft Access SQL中编写此查询,但就我而言,我无法弄清楚代码中的语法错误。
SELECT base.study_group, base.NPI,inv.log_date AS invite_date, rec.log_date as
recieved_date, rej.log_date as reject_date
FROM CODAAC_master AS base
LEFT JOIN Pre_Log AS inv ON base.NPI = inv.NPI AND inv.tracking_event='INVA'
LEFT JOIN Pre_Log AS rec ON base.NPI = rec.NPI AND rec.tracking_event='RECA'
LEFT JOIN Pre_Log AS rej ON base.NPI = rej.NPI AND rej.tracking_event='REJA'
WHERE base.study_year = '2013'
ORDER BY base.study_group, base.NPI;
我得到的错误是:
"Syntax error (missing operator) in query expression"
答案 0 :(得分:3)
MS Access需要围绕多个联接的括号:
SELECT base.study_group,
base.NPI,
inv.log_date AS invite_date,
rec.log_date as recieved_date,
rej.log_date as reject_date
FROM ((CODAAC_master AS base
LEFT JOIN Pre_Log AS inv
ON base.NPI = inv.NPI AND inv.tracking_event='INVA')
LEFT JOIN Pre_Log AS rec
ON base.NPI = rec.NPI AND rec.tracking_event='RECA')
LEFT JOIN Pre_Log AS rej
ON base.NPI = rej.NPI AND rej.tracking_event='REJA'
WHERE base.study_year = '2013'
ORDER BY base.study_group, base.NPI;
答案 1 :(得分:3)
您需要在连接之间添加括号,因为它在MS Access上是必不可少的。 (这在其他RDBMS上是可选的)
SELECT base.study_group,
base.NPI,
inv.log_date AS invite_date,
rec.log_date as recieved_date,
rej.log_date as reject_date
FROM ((CODAAC_master AS base LEFT JOIN Pre_Log AS inv
ON base.NPI = inv.NPI AND inv.tracking_event='INVA')
LEFT JOIN Pre_Log AS rec
ON base.NPI = rec.NPI AND rec.tracking_event='RECA')
LEFT JOIN Pre_Log AS rej
ON base.NPI = rej.NPI AND rej.tracking_event='REJA'
WHERE base.study_year = '2013'
ORDER BY base.study_group, base.NPI;