我需要选择非官方 lang-s 是官方两倍的国家,+ 官员是 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:额外 ( 加入
NExt错误:无法识别内部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(:"有子句"中的未知列"cisT.isOffTrue">
加法:
桌子:
+-------------+---------------+------+-----+--------+
| Field | Type | Null | Key | Default |
+-------------+---------------+------+-----+---------+
| CountryCode | char(3) | NO | PRI | |
| Language | char(30) | NO | PRI | |
| IsOfficial | enum('T','F') | NO | | F |
+-------------+---------------+------+-----+---------+
我像下一个一样更改了查询,它起作用了,买我仍然没有得到以前失败的 RC
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);
您正在加入
ON cisT.countrycode = c2.countrycode
但 cisT 表中不存在国家/地区代码列。