作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在尝试根据游戏 ID 获取平台名称。
我有如下三个表,我正在尝试连接它们以获得所需的结果:
Games
Id | .....| .....|
---|------ ------|
1 | . | . |
2 | . | . |
3 | . | . |
4 | . | . |
Game_Platforms
Id |....|game_id| platform_id|...|
---------------------------------
1 | . | 1 | 1 |.. |
2 | . | 1 | 2 |.. |
3 | . | 3 | 3 |.. |
.. | . | 4 | 4 |.. |
Platforms
Id| ...|...| name |
---------------------|
1 | . | . | iOS |
2 | . | . | Android |
3 | . | . | Windows |
4 | . | . | SteamOS |
type Platforms struct {
Name string
}
var name []Platforms
query = postgres.Db().Select("name").
Joins("JOIN games ON games.id = game_platforms.game_id").
Joins("JOIN game_platforms ON game_platforms.platform_id = platforms.id").
Where("games.id = 1").Find(&name)
我希望获得平台名称,但出现错误:
pq: missing FROM-clause entry for table "game_platforms"
我认为我写的 Joins 命令不正确,但看起来合乎逻辑,也许我错了。
最佳答案
您的查询缺少 FROM
子句。
我假设您想从 platforms
表中选择数据。如果是,那么(根据您的代码)您应该首先加入 game_platforms
,然后加入 games
。
query = postgres.Db().Select("name").
Find("platforms"). // <------ this one
Joins("JOIN game_platforms ON game_platforms.platform_id = platforms.id").
Joins("JOIN games ON games.id = game_platforms.game_id").
Where("games.id = 1").Find(&name)
关于postgresql - 如何修复 "missing FROM-clause entry for table"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288132/
我是一名优秀的程序员,十分优秀!