MySQL 1054-字段列表中的未知列“lat”

MySQL 1054-字段列表中的未知列“lat”,mysql,Mysql,我正在尝试合并两个MySQL语句,我想我已经接近解决这个问题了,但是我在“字段列表”中得到了1054-未知列“lat”,这是指下面的粗体文本 我试着把lat和lng文本包含在一起,甚至“没有效果” SELECT post_attributes_3.value AS name, clean, post_attributes.value AS lat, post_attributes_1.value AS lng, post_attributes_2.value AS category, ( 395

我正在尝试合并两个MySQL语句,我想我已经接近解决这个问题了,但是我在“字段列表”中得到了1054-未知列“lat”,这是指下面的粗体文本

我试着把lat和lng文本包含在一起,甚至“没有效果”

SELECT post_attributes_3.value AS name, clean, post_attributes.value AS lat, post_attributes_1.value AS lng, post_attributes_2.value AS category, ( 3959 * acos( cos( radians('%s') ) * cos( radians( **lat** ) ) * cos( radians( **lng** ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( **lat** ) ) ) ) AS distance
FROM post_attributes AS post_attributes_3 INNER JOIN ((post_attributes AS post_attributes_1 INNER JOIN (posts INNER JOIN post_attributes ON posts.id = post_attributes.post_id) ON post_attributes_1.post_id = posts.id) INNER JOIN post_attributes AS post_attributes_2 ON posts.id = post_attributes_2.post_id) ON post_attributes_3.post_id = posts.id
WHERE (((post_attributes_3.name)="name") AND ((post_attributes_2.name)="category_id") AND ((post_attributes.name)="lat") AND ((post_attributes_1.name)="lng"))
HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20;
这两个MySQL语句可以单独使用,但可能与AS语句的使用有关


更新:感谢大家的帮助,但由于使用此select查询的方式,我选择创建一个MySQL视图,并使用它运行与第一个类似的SQL命令。

尝试用真实列名替换别名:

SELECT post_attributes_3.value AS name, clean, post_attributes.value AS lat, post_attributes_1.value AS lng, post_attributes_2.value AS category, ( 3959 * acos( cos( radians('%s') ) * cos( radians( post_attributes.value ) ) * cos( radians( post_attributes_1.value ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( post_attributes.value ) ) ) ) AS distance
FROM post_attributes AS post_attributes_3 INNER JOIN ((post_attributes AS post_attributes_1 INNER JOIN (posts INNER JOIN post_attributes ON posts.id = post_attributes.post_id) ON post_attributes_1.post_id = posts.id) INNER JOIN post_attributes AS post_attributes_2 ON posts.id = post_attributes_2.post_id) ON post_attributes_3.post_id = posts.id
WHERE (((post_attributes_3.name)="name") AND ((post_attributes_2.name)="category_id") AND ((post_attributes.name)="lat") AND ((post_attributes_1.name)="lng"))
HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20;

最后一个查询导致错误,这也是您遇到的问题。

尝试用真实列名替换别名:

SELECT post_attributes_3.value AS name, clean, post_attributes.value AS lat, post_attributes_1.value AS lng, post_attributes_2.value AS category, ( 3959 * acos( cos( radians('%s') ) * cos( radians( post_attributes.value ) ) * cos( radians( post_attributes_1.value ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( post_attributes.value ) ) ) ) AS distance
FROM post_attributes AS post_attributes_3 INNER JOIN ((post_attributes AS post_attributes_1 INNER JOIN (posts INNER JOIN post_attributes ON posts.id = post_attributes.post_id) ON post_attributes_1.post_id = posts.id) INNER JOIN post_attributes AS post_attributes_2 ON posts.id = post_attributes_2.post_id) ON post_attributes_3.post_id = posts.id
WHERE (((post_attributes_3.name)="name") AND ((post_attributes_2.name)="category_id") AND ((post_attributes.name)="lat") AND ((post_attributes_1.name)="lng"))
HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20;

最后一个查询导致错误,这也是您遇到的问题。

描述post\u属性?描述分类?确保所有表引用都有别名。尝试使用别名前缀post_attributes_2。lat MySQL可能需要确切地知道要从哪个表行获取“lat”。post_attributes表包含post_id、名称和值,此表用于存储有关post的不同类型的信息,其中之一是lat和lng值。类别表包含id和名称。有人按照相同的行回答了。为categorize引入一个表别名,然后将从中间SQL复制的每个列引用(如名称)替换为cat.name,这将包括cat.lat。当可能存在多个名为lng的列时,需要使用表别名来消除所引用数据的歧义。请描述post_属性?描述分类?确保所有表引用都有别名。尝试使用别名前缀post_attributes_2。lat MySQL可能需要确切地知道要从哪个表行获取“lat”。post_attributes表包含post_id、名称和值,此表用于存储有关post的不同类型的信息,其中之一是lat和lng值。类别表包含id和名称。有人按照相同的行回答了。为categorize引入一个表别名,然后将从中间SQL复制的每个列引用(如名称)替换为cat.name,这将包括cat.lat。当可能存在多个名为lng的列时,需要使用表别名来消除您引用的数据的歧义。感谢Jocelyn,它没有返回任何错误,希望是这样。我似乎仍然无法从数据库中获取任何数据,以下链接使用的是第一条SQL语句。我更改了这个新文件中的select命令,但它没有返回任何内容:谢谢Jocelyn,它没有返回任何错误,希望是这样。我似乎仍然无法从数据库中获取任何数据,以下链接使用的是第一条SQL语句。我更改了此新文件中的select命令,但它没有返回任何内容:
SELECT post_attributes_3.value AS name, clean, post_attributes.value AS lat, post_attributes_1.value AS lng, post_attributes_2.value AS category, ( 3959 * acos( cos( radians('%s') ) * cos( radians( post_attributes.value ) ) * cos( radians( post_attributes_1.value ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( post_attributes.value ) ) ) ) AS distance
FROM post_attributes AS post_attributes_3 INNER JOIN ((post_attributes AS post_attributes_1 INNER JOIN (posts INNER JOIN post_attributes ON posts.id = post_attributes.post_id) ON post_attributes_1.post_id = posts.id) INNER JOIN post_attributes AS post_attributes_2 ON posts.id = post_attributes_2.post_id) ON post_attributes_3.post_id = posts.id
WHERE (((post_attributes_3.name)="name") AND ((post_attributes_2.name)="category_id") AND ((post_attributes.name)="lat") AND ((post_attributes_1.name)="lng"))
HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20;