牛骨文教育服务平台(让学习变的简单)
博文笔记

Mysql两个查询结果相加?错误:Every derived table must have its own alias

创建时间:2016-04-12 投稿人: 浏览次数:2252
SELECT username,SUM(ycnum) AS yznum,SUM(zfnum) AS zfnum
FROM
(select * from tempactive where exists 
(select * from topic1activeuser where username=tempactive.username) 
UNION
select * from topic1activeuser where exists 
(select * from tempactive where username=topic1activeuser.username)) 
GROUP BY username

一直报错Every derived table must have its own alias 

提示要给子查询加上别名

SELECT username,SUM(ycnum) AS yznum,SUM(zfnum) AS zfnum
FROM
(select * from tempactive where exists 
(select * from topic1activeuser where username=tempactive.username) 
UNION
select * from topic1activeuser where exists 
(select * from tempactive where username=topic1activeuser.username)) 
AS total
GROUP BY username


结果:



select * from tempactive where exists 
(select * from topic1activeuser where username=tempactive.username)

结果1:


select * from topic1activeuser where exists 
(select * from tempactive where username=topic1activeuser.username)

结果2:



声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。