在MySQL中的“Where Clause”中出现未知列。

huangapple go评论52阅读模式
英文:

Unknown Column in 'Where Clause' (mysql)

问题

我正在尝试将一个视图导入到我的数据库中,执行以下操作:

create algorithm = UNDEFINED 
       definer = `adbo_boletines_3` @`localhost` 
       sql security 
       definer view `adbo_boletines_3`.`postcategories` as 
select
    `p`.`ID` as `ID`,
    `p`.`post_author` as `post_author`,
    `p`.`post_date` as `post_date`,
    `p`.`post_date_gmt` as `post_date_gmt`,
    `p`.`post_content` as `post_content`,
    `p`.`post_title` as `post_title`,
    `p`.`post_excerpt` as `post_excerpt`,
    `p`.`post_status` as `post_status`,
    `p`.`comment_status` as `comment_status`,
    `p`.`ping_status` as `ping_status`,
    `p`.`post_password` as `post_password`,
    `p`.`post_name` as `post_name`,
    `p`.`to_ping` as `to_ping`,
    `p`.`pinged` as `pinged`,
    `p`.`post_modified` as `post_modified`,
    `p`.`post_modified_gmt` as `post_modified_gmt`,
    `p`.`post_content_filtered` as `post_content_filtered`,
    `p`.`post_parent` as `post_parent`,
    `p`.`guid` as `guid`,
    `p`.`menu_order` as `menu_order`,
    `p`.`post_type` as `post_type`,
    `p`.`post_mime_type` as `post_mime_type`,
    `p`.`comment_count` as `comment_count`,
    cast(`p`.`post_date` as date) as `fecha`,
    `r`.`term_taxonomy_id` as `term_taxonomy_id`,
    `t`.`parent` as `parent`,
    `c`.`name` as `name`,
    (
    select
        `cs`.`name`
    from
        ((`wp_term_relationships` `rs`
    join `wp_term_taxonomy` `ts`)
    join `wp_terms` `cs`)
    where
        `rs`.`term_taxonomy_id` = `ts`.`term_taxonomy_id`
        and `ts`.`term_id` = `cs`.`term_id`
        and `ts`.`parent` = 456
        and `rs`.`object_id` = `p`.`ID`
    limit 1) as `pais`
from
    (((`wp_posts` `p`
join `wp_term_relationships` `r`)
join `wp_term_taxonomy` `t`)
join `wp_terms` `c`)
where
    `p`.`ID` = `r`.`object_id`
    and `r`.`term_taxonomy_id` = `t`.`term_taxonomy_id`
    and `t`.`term_id` = `c`.`term_id`;

在执行查询后出现以下错误:

MySQL 返回:

#1054 - 未知列 'c.term_id`term_id' 在 'where 子句' 中

我不太确定如何处理这个问题,或者如何修复查询以使其通过。

谢谢!

英文:

I am trying to import a view into my database, doing the following:

create algorithm = UNDEFINED 
definer = `adbo_boletines_3` @`localhost` 
sql security 
definer view `adbo_boletines_3`.`postcategories` as 
select
`p`.`ID` as `ID`,
`p`.`post_author` as `post_author`,
`p`.`post_date` as `post_date`,
`p`.`post_date_gmt` as `post_date_gmt`,
`p`.`post_content` as `post_content`,
`p`.`post_title` as `post_title`,
`p`.`post_excerpt` as `post_excerpt`,
`p`.`post_status` as `post_status`,
`p`.`comment_status` as `comment_status`,
`p`.`ping_status` as `ping_status`,
`p`.`post_password` as `post_password`,
`p`.`post_name` as `post_name`,
`p`.`to_ping` as `to_ping`,
`p`.`pinged` as `pinged`,
`p`.`post_modified` as `post_modified`,
`p`.`post_modified_gmt` as `post_modified_gmt`,
`p`.`post_content_filtered` as `post_content_filtered`,
`p`.`post_parent` as `post_parent`,
`p`.`guid` as `guid`,
`p`.`menu_order` as `menu_order`,
`p`.`post_type` as `post_type`,
`p`.`post_mime_type` as `post_mime_type`,
`p`.`comment_count` as `comment_count`,
cast(`p`.`post_date` as date) as `fecha`,
`r`.`term_taxonomy_id` as `term_taxonomy_id`,
`t`.`parent` as `parent`,
`c`.`name` as `name`,
(
select
`cs`.`name`
from
((`wp_term_relationships` `rs`
join `wp_term_taxonomy` `ts`)
join `wp_terms` `cs`)
where
`rs`.`term_taxonomy_id` = `ts`.`term_taxonomy_id`
and `ts`.`term_id` = `cs`.`term_id`
and `ts`.`parent` = 456
and `rs`.`object_id` = `p`.`ID`
limit 1) as `pais`
from
(((`wp_posts` `p`
join `wp_term_relationships` `r`)
join `wp_term_taxonomy` `t`)
join `wp_terms` `c`)
where
`p`.`ID` = `r`.`object_id`
and `r`.`term_taxonomy_id` = `t`.`term_taxonomy_id`
and `t`.`term_id` = `c`.`term_id``term_id`;

and getting this error after executing the query

> MySQL said:
>
> #1054 - Unknown column 'c.term_id`term_id' in 'where clause'

im not really sure what to do here, or how to fix the query so it can pass.

thanks!

答案1

得分: 0

这是额外的文本,最后有一个 term_id。可能是在 where 子句中的字段只有 c.term_id

也就是说,将以下语法更改为:

AND `t`.`term_id` = `c`.`term_id``term_id`;

改为

AND `t`.`term_id` = `c`.`term_id`;
英文:

the is an extra text term_id in the end. probably the field in the where clause is c.term_id only.

that said, change the following sintax:

AND `t`.`term_id` = `c`.`term_id``term_id`;

to

AND `t`.`term_id` = `c`.`term_id`;

huangapple
  • 本文由 发表于 2023年1月9日 00:47:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049608.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定