我需要选择非官方语言比官方语言多两倍的国家,+官方语言是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);
1条答案
按热度按时间nfs0ujit1#
你要加入吗
在cist.countrycode=c2.countrycode上
但cist表中不存在countrycode列。