计算A子查询中的不同值 [英] Count Distinct Values in A sub query

查看:75
本文介绍了计算A子查询中的不同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......
我正在使用sqlserevr 2000
我的问题是

我想连续计算不同的值

hi....
i am using sqlserevr 2000
my problem is

i want to count the distinct values in a row

create table counting(id int identity(1,1),[name] varchar(20),c1 varchar(10),c2 varchar(10),c3 varchar(10),[count] int default 0)

insert into counting([name],c1,c2,c3) values(aravind,AA,BB,CC)
insert into counting([name],c1,c2,c3) values(aravd,AA,AA,DD)
insert into counting([name],c1,c2,c3) values(avid,AA,AA,AA)
insert into counting([name],c1,c2,c3) values(a,AA,B,BB)
insert into counting([name],c1,c2,c3) values(arnd,EE,FF,JJ)


现在我想计算一行的c1,c2,c3的不同值

例如对于第1行count = 3
对于第1行count = 2,而不使用临时表

在此先感谢


now i want to count the distinct values from c1,c2,c3 of one row

for example for row 1 count=3
for row 1 count=2 without using temp table

thanks in advance

推荐答案

如果重复列的值,那么最好对表进行规范化并创建另一个表来保存这些值,从那里选择一个不重复计数
If the columns values are repeated then you would be better of normalizing the table and creating another table to hold those values, from there it just a select distinct count


这篇关于计算A子查询中的不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆