列查询不明确 [英] Ambiguous column query

查看:90
本文介绍了列查询不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此查询时出现模糊列"错误,但是我很难找到原因:

I'm getting the "ambiguous column" error when running this query, but I'm having a hard time finding the cause:

select bobooks.ID request,    
       bobooks.TITLE,    
       bobooks.AUTHOR,    
       bogenres.NAME genre,    
       bobooks.OWNER,    
       bostatus.NAME status,    
       bolanguages.LANGUAGE language,    
       bolanguages2.LANGUAGE secondary_language    
from BO_BOOKS bobooks    
inner join BO_GENRES bogenres
  on bobooks.genre = bogenres.id    
inner join BO_STATUS bostatus
  on bobooks.status = bostatus.id    
inner join BO_LANGUAGES bolanguages
  on bobooks.language = bolanguages.id    
left outer join BO_LANGUAGES bolanguages2
  on bobooks.secondary_language = bolanguages2.id    
where (replace(:P19_AUTHOR, ' ', '') = '' or
       bobooks.author like '%'||:P19_AUTHOR||'%') AND    
      (replace(:P19_TITLE, ' ', '') = '' or
       bobooks.title like '%'||:P19_TITLE||'%') AND    
      (:P14_LANGUAGE = 'all' or
       language = :P19_LANGUAGE or
       secondary_language = :P19_LANGUAGE) AND
      (:P19_GENRE = 'all' or
       genre = :P19_GENRE) AND
      (replace(:P19_OWNER, ' ', '') = ''  or
       bobooks.owner like '%'||:P19_OWNER||'%');

我搞砸了哪几列?

非常感谢您抽出宝贵的时间!

Thank you so much for your time!

推荐答案

您不能在WHERE子句中的SELECT子句中引用列别名,至少不能在同一查询中引用.您可以对其进行子查询,也可以只使用原始的列引用.

You can NOT reference column aliases in the SELECT clause within the WHERE clause, at least not in the same query. You could subquery it, or just use the original column references.

select     
 bobooks."ID" request,    
 bobooks."TITLE",    
 bobooks."AUTHOR",    
 bogenres."NAME" genre,    
 bobooks."OWNER",    
 bostatus."NAME" status,    
 bolanguages."LANGUAGE" language,    
 bolanguages2."LANGUAGE" secondary_language    
from BO_BOOKS bobooks    
inner join    
BO_GENRES bogenres on bobooks.genre = bogenres.id    
inner join     
BO_STATUS bostatus on bobooks.status = bostatus.id    
inner join     
BO_LANGUAGES bolanguages on bobooks.language = bolanguages.id    
left outer join    
BO_LANGUAGES bolanguages2 on bobooks.secondary_language = bolanguages2.id    
where     
(replace(:P19_AUTHOR, ' ', '') = '' 
or
bobooks.author like '%'||:P19_AUTHOR||'%')
AND    
(replace(:P19_TITLE, ' ', '') = '' 
or
bobooks.title like '%'||:P19_TITLE||'%')
AND    
(:P14_LANGUAGE = 'all' 
or
bolanguages."LANGUAGE" = :P19_LANGUAGE
or
bolanguages2."LANGUAGE" = :P19_LANGUAGE)
AND
(:P19_GENRE = 'all' 
or
bogenres."NAME" = :P19_GENRE)
AND
(replace(:P19_OWNER, ' ', '') = '' 
or
bobooks.owner like '%'||:P19_OWNER||'%');

这篇关于列查询不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆