简体   繁体   English

在子查询中使用外部查询值-出现错误:“无此列……”

[英]Using outer query value in sub-query - Getting error : “no such column … ”

I am grouping my outer query based on a column. 我正在基于列对外部查询进行分组。 I then want to use the value from the specific column in an inner query that is performing some other calculation using that column's value. 然后,我想在内部查询中使用特定列的值,该查询使用该列的值执行其他计算。

I get the error "No such column .... " 我收到错误“没有这样的列...。”

Here is my query: 这是我的查询:

SELECT 
    language AS outer_language, <--- This is the value I want to use
    COUNT(*) / (SELECT 
            COUNT(*)
        FROM
            e_lan_specs AS e
                INNER JOIN
             ue_lan_info_spec AS ue ON ue.lan_specs_id = e.id
                INNER JOIN
            u_lan_info AS u ON u.id = ue.lan_info_id
        WHERE
            u.language = outer_language) as perc_avg,
    first,
    second,
    third,
    fourth
FROM
    e_lan_specs AS e
        INNER JOIN
     ue_lan_info_spec AS ue ON ue.lan_specs_id = e.id
        INNER JOIN
    u_lan_info AS u ON u.id = ue.lan_info_id
GROUP BY first , second , third , fourth , language

You can't do that. 你不能那样做。 You have to use language with the appropriate alias. 您必须使用具有适当别名的language Something like: 就像是:

SELECT language AS outer_language, <--- This is the value I want to use
       COUNT(*) / (SELECT COUNT(*)
                   FROM e_lan_specs AS e2 INNER JOIN
                        ue_lan_info_spec AS ue2
                        ON ue2.lan_specs_id = e2.id INNER JOIN
                        u_lan_info AS u2
                        ON u2.id = ue2.lan_info_id
                   WHERE u2.language = u.outer_language
                  ) as perc_avg,
       . . .

The problem is that the select clause is what gives the language column its alias as outer_language. 问题在于select子句为语言列提供了别名external_language。 You can't use the alias within the same statement that creates it. 您不能在创建别名的同一语句中使用别名。

Try: 尝试:

SELECT language AS outer_language, <--- This is the value I want to use
    COUNT(*) / (SELECT 
            COUNT(*)
        FROM
            e_lan_specs AS e
                INNER JOIN
             ue_lan_info_spec AS ue ON ue.lan_specs_id = e.id
                INNER JOIN
            u_lan_info AS u2 ON u2.id = ue.lan_info_id
        WHERE
            u.language = u2.language) as perc_avg,
    first,
    second,
    third,
    fourth
FROM
    e_lan_specs AS e
        INNER JOIN
     ue_lan_info_spec AS ue ON ue.lan_specs_id = e.id
        INNER JOIN
    u_lan_info AS u ON u.id = ue.lan_info_id
GROUP BY first , second , third , fourth , language

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM