错误1248(42000):每个派生表都必须有自己的别名,别名存在(内部查询带有group和having)

wd2eg0qa  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(347)

我需要选择非官方语言比官方语言多两倍的国家,+官方语言是2+
mysql查询:

SELECT c2.countrycode , sum(c2.isOfficial) as isFalse
FROM countrylanguage as c2
 INNER JOIN (
        select c.countrycode , sum(c.isOfficial)as isOffTrue 
        from countrylanguage as c 
        where c.isOfficial='T' 
        group by c.countrycode 
        having sum(c.isOfficial)>1)
         ) as cisT 
 ON cisT.countrycode = c2.countrycode 
  where c2.isOfficial='F' 
  group by c2.countrycode 
  having sum(c2.isOfficial)>cisT.isOffTrue*2

但是我遇到了别名错误,并且无法确定问题的根本原因,您能帮我吗?
稍后。。。。
rc:额外)连接
下一个错误:无法识别internal sum()别名,您能帮忙吗?

SELECT c2.countrycode , sum(c2.isOfficial) as isFalse
FROM countrylanguage as c2
 INNER JOIN (
        select c.countrycode , sum(c.isOfficial) isOffTrue 
        from countrylanguage as c 
        where c.isOfficial='T' 
        group by c.countrycode 
        having sum(c.isOfficial)>1
         ) as cisT 
 ON cisT.countrycode = c2.countrycode 
  where c2.isOfficial='F' 
  group by c2.countrycode 
  having sum(c2.isOfficial)>(cisT.isOffTrue*2);

错误1054(42s22):“having子句”中的未知列“cist.isofftrue”
附加:
表格:

+-------------+---------------+------+-----+--------+
| Field       | Type          | Null | Key | Default |
+-------------+---------------+------+-----+---------+
| CountryCode | char(3)       | NO   | PRI |         |
| Language    | char(30)      | NO   | PRI |         |
| IsOfficial  | enum('T','F') | NO   |     | F       |
+-------------+---------------+------+-----+---------+

我改变了像下一个查询,它的工作,但我仍然没有得到以前失败的钢筋混凝土

SELECT c2.countrycode, sum(c2.isOfficial) as isOffFalse, c1.isOffTrue 
  FROM (
select c0.countrycode, sum(c0.isOfficial)as isOffTrue 
from countrylanguage c0 
where c0.isOfficial='T' 
group by c0.countrycode having sum(isOfficial)>1
) as c1, countrylanguage as c2
  where c1.countrycode = c2.countrycode 
and c2.isOfficial='F' 
group by c2.countrycode 
having sum(c2.isOfficial)>(c1.isOffTrue*2);
nfs0ujit

nfs0ujit1#

你要加入吗
在cist.countrycode=c2.countrycode上
但cist表中不存在countrycode列。

相关问题