gpt4 book ai didi

sql - 联合操作后如何获取记录数..?

转载 作者:搜寻专家 更新时间:2023-10-30 21:42:58 25 4
gpt4 key购买 nike

我有这样的查询:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com