0

无效的 SQL:

SELECT
 info_hash,
 size,
 comment,
 created_by,
 announce_list,
 completed_by, 
 completed,
 seeders,
 leechers,
 ulspeed,
 dlspeed,
 dateline,
 thumbnail_dateline, 
 filename,
 filesize,
 visible,
 attachmentid,
 counter,
 postid, 
 IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail,
 thumbnail_filesize,
 attachmenttype.thumbnail AS build_thumbnail,
 attachmenttype.newwindow
FROM attachment
LEFT JOIN attachmenttype AS attachmenttype USING (extension)
WHERE postid IN (-1,2)
ORDER BY attachmentid;

MySQL 错误:字段列表中的列“大小”不明确错误号:1052

4

2 回答 2

3

这意味着size大概在attachmentattachmenttype中。

如果您限定列名,那么您将永远不会遇到此类问题。

于 2017-10-04T00:49:42.720 回答
1

@GordonLinoff 有正确的答案。但是,如果您只是从某个地方复制此代码,那么您将很难理解他在说什么。(也很好地询问更好)。

以此为基础。请注意我如何添加A.size如果任何字段再次不正确,您将不得不添加其中一个A.或添加T.到它。

SELECT info_hash, 
 A.size,
 comment,
 created_by,
 announce_list,
 completed_by, 
 completed, 
 seeders, 
 leechers, 
 ulspeed, 
 dlspeed,
 dateline, 
 thumbnail_dateline, 
 filename, 
 filesize, 
 visible,
 attachmentid, 
 counter,
 postid,
 IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail,
 thumbnail_filesize,
 T.thumbnail AS build_thumbnail, 
 T.newwindow
FROM attachment A
LEFT JOIN attachmenttype AS T USING (extension)
WHERE A.postid IN (-1,2)
ORDER BY A.attachmentid;
于 2017-10-04T02:11:58.747 回答