读书人

这个SQL语句如何不能执行?关于union

发布时间: 2013-08-09 15:16:24 作者: rapoo

这个SQL语句怎么不能执行?关于union all
select count(*)
from
(
select id from tb
union all
select id from tb
)

这是怎么回事?
[解决办法]
select count(*)
from
(
select id from tb
union all
select id from tb
)T 这样就可以了 括号后面字母随便你取
[解决办法]
--括号里面的东东是一个子查询,是必须要加别名的。select count(*) from (...) as T
[解决办法]


--楼主少了一个别名
select count(*)
from
(
select id from tb
union all
select id from tb
) a

[解决办法]

select count(*)
from
(
select id from tb
union all
select id from tb
)a
--加个别名就可以

[解决办法]
from后面一定要接个表名,你括号内其实是个数据集,你要给这个数据集起个名字才能查询

select count(*)
from
(
select id from tb
union all
select id from tb
) a

读书人网 >SQL Server

热点推荐