如何在MS ACCESS 2016语法中编写以下SQL查询?
SELECT
ticket.ticket_id,
a1.attr_val AS attr_val1,
a2.attr_val AS attr_val2,
a3.attr_val AS attr_val3
FROM ticket
LEFT JOIN attr a1 ON ticket.ticket_id=a1.ticket_id AND a1.attr_type=1
LEFT JOIN attr a2 ON ticket.ticket_id=a2.ticket_id AND a2.attr_type=2
LEFT JOIN attr a3 ON ticket.ticket_id=a3.ticket_id AND a3.attr_type=3
提前感谢您的帮助!
答案 0 :(得分:1)
MS Access具有以下weird requirements about parentheses:
不支持连接表达式。 (错误3296)
可能的原因:
- 您的SQL语句包含多个联接,其中查询的结果可能会有所不同,具体取决于执行联接的顺序。您可能希望创建单独的查询以执行第一个连接,然后在SQL语句中包含该查询。
ON
操作中的JOIN
语句不完整或包含的表太多。您可能希望将ON
表达式放在WHERE
子句中。
上述引文中建议的解决方案并不总是合适的(例如,使用WHERE
子句不是LEFT JOIN
条件的选项。
ON
表达式; SELECT
ticket.ticket_id,
a1.attr_val AS attr_val1,
a2.attr_val AS attr_val2,
a3.attr_val AS attr_val3
FROM ((ticket
LEFT JOIN attr AS a1 ON (ticket.ticket_id=a1.ticket_id AND a1.attr_type=1))
LEFT JOIN attr AS a2 ON (ticket.ticket_id=a2.ticket_id AND a2.attr_type=2))
LEFT JOIN attr AS a3 ON (ticket.ticket_id=a3.ticket_id AND a3.attr_type=3)