informix 数据查询中多个count(distinct )报错
例:selecta.name,count(distincta.num),count(distinctb.id),count(distinctb.name)froma,bw...
例:select a.name,count(distinct a.num),count(distinct b.id),count(distinct b.name)
from a,b
where a.ii=b.ii;
这样写第二个count那会报错,如果去掉第二三个的distinct就没事,请问应该怎么写? 展开
from a,b
where a.ii=b.ii;
这样写第二个count那会报错,如果去掉第二三个的distinct就没事,请问应该怎么写? 展开
展开全部
select x.name,y.count_b,z.count_c
from
(
select a.name,count(distinct a.num) as count_a
from a,b
where a.ii=b.ii
group by a.name
) x join
(
select a.name,count(distinct b.id) as count_b
from a,b
where a.ii=b.ii
group by a.name
) y on x.name = y.name
join
(
select a.name,count(distinct b.name) as count_c
from a,b
where a.ii=b.ii
group by a.name
) z on x.name = z.name
from
(
select a.name,count(distinct a.num) as count_a
from a,b
where a.ii=b.ii
group by a.name
) x join
(
select a.name,count(distinct b.id) as count_b
from a,b
where a.ii=b.ii
group by a.name
) y on x.name = y.name
join
(
select a.name,count(distinct b.name) as count_c
from a,b
where a.ii=b.ii
group by a.name
) z on x.name = z.name
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select a.name, a.num, b.id, b.name, count(*)
from a,b
where a.ii=b.ii
group by 1,2,3,4;
追问
这条语句没错,但是不是我想要得到的结果,我就是想用一个语句就把id数、name总数,num数汇总出来,且不能有重复值。而你给的结果不是。
这条语句没错,但是不是我想要得到的结果,我就是想用一个语句就把id数、name总数,num数汇总出来,且不能有重复值。而你给的结果不是。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询