gpt4 book ai didi

sql - 在 Access 中加入语法

转载 作者:行者123 更新时间:2023-12-04 17:53:03 24 4
gpt4 key购买 nike

我正在使用 Access 权限,并且有两个表:

观点:

id,x,y
1 32432432 143423232
2 32432443 143423300

线:
id startPoint endPoint
1 1 2

现在,当我查询该行时,我希望返回的表将包含 startPoint 和 endPoint 的 x,y。

我试过加入:
select line.*,point.x as x1,point.y as y1 from line as line join point as point on line.startPoint=point.id where line.id=1;

然后我可以得到以下只包含 startPoint 的结果。
id startPoint endPoint x1 y1
1 1 2 ......

然后如何检索端点,而我想要这样的结果(x2 y2 是端点的坐标):
id startPoint endPoint x1 y1 x2 y2
1 1 2 ......

我试了两个 join ,但它不起作用。
select line.*,point1.x as x1,point1.y as y1,point2.x as x2,point.y as y2 from line as line left join point1 as point on line.startPoint=point1.id  left join point as point2 on line.endPoint=point2.id where line.id=1;

最佳答案

Access 对多个连接有奇怪的语法规则。你必须像这样把它们放在括号里。

select line.*, point1.x as x1,point1.y as y1,
point2.x as x2, point.y as y2
from (line as line
left join point as point1
on line.startPoint = point1.id)
left join point as point2
on line.endPoint = point2.id
where line.id = 1;

每个附加连接都需要在第一个表之前的另一个左括号和倒数第二个连接之后的右括号。

关于sql - 在 Access 中加入语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12810409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com