You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL查询报错:spel_plattform表FROM子句缺失及平台全名获取咨询

问题解答

1. 修复SQL查询的报错

你遇到的错误是因为查询里用到了spel_plattform表,但没把它加入查询的表列表,而且关联逻辑也不对。正确的做法是先把Spel和中间表spel_plattform通过spelid关联,再用spel_plattform里的plattformID关联Plattform表,这样才能拿到游戏和对应平台的正确数据。

修正后的完整查询(获取游戏名+完整平台名称):

SELECT Spel.spel, Plattform.Plattform AS 完整平台名称
FROM Spel
JOIN spel_plattform ON Spel.SpelID = spel_plattform.spelID
JOIN Plattform ON spel_plattform.plattformID = Plattform.PlattformID;

如果只需要平台ID,修正后的基础查询:

SELECT Spel.spel, spel_plattform.plattformID
FROM Spel
JOIN spel_plattform ON Spel.SpelID = spel_plattform.spelID;

2. 无外键时能否获取完整平台名称

完全可以。外键只是数据库用来保证数据一致性的约束(比如阻止插入不存在的平台ID),它不影响表之间的查询关联。只要两个表有共同的关联字段(比如spel_plattform的plattformID和Plattform的PlattformID),就算没有外键,也能通过关联查询拿到对应的完整平台名称。

内容的提问来源于stack exchange,提问作者medina_01

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 12:13:15