我有这样的查询:
select author1
from books_group
where category='cse'
union
select author2
from books_group
where category='cse'
union
select author3
from books_group
where category='cse'
上面的查询合并了来自三个选择命令的所有记录..
我的任务是计算执行上述sql命令后我们拥有的记录数...
我尝试了下面的查询,但它给出了一个错误..
"select count(*) from (select author1 from books_group where category='cse' union select author2 from books_group where category='cse' union select author3 from books_group where category='cse') "
那么union运算后如何获取记录数..???
最佳答案
你很接近,你需要为你的子选择指定一个别名:
select
count(*)
from
(
select author1 from books_group where category='cse' union
select author2 from books_group where category='cse' union
select author3 from books_group where category='cse'
) a
关于sql - 联合操作后如何获取记录数..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5204999/