txt数据库字段中记录了N条数据,每个条记录都是记录的数字,用|分隔的。大家帮我看看怎么统计到这些记录中都有哪些数字,(排除重复的),并且如果有重复的,读取它重复过多少次。请大家指点,谢谢。
细心的高手最好能为我提供C#代码,谢谢了,在线等。

解决方案 »

  1.   

    先把数据导入到数据库然后处理一下就可以了。create table txttable(col int,col2 int,col3 int,col4 int,col5 int)
    insert into txttable
    select 3,1,5,null,null union all
    select 1,10,20,30,40 union all
    select 12,43,45,null,null union all
    select 10,34,null,null,null union all
    select 12,68,null,null,null union all
    select 45,17,36,null,null union all
    select 12,36,89,55,69 union all
    select 45,69,56,33,20 union all
    select 45,40,58,25,17
    go
     
    create function [dbo].[f_GetCount]
    (
    @s int                    
    )
    returns int
    as  
    begin  
       declare @i intselect @i=count(1) from txttable where col=@s
    select @i=@i+count(1) from txttable where col2=@s
    select @i=@i+count(1) from txttable where col3=@s
    select @i=@i+count(1) from txttable where col4=@s
    select @i=@i+count(1) from txttable where col5=@s
    return @i
    end  goselect col as 数字,dbo.[f_GetCount](col) as 个数 from (
    select col from txttable union 
    select col2 from txttable union 
    select col3 from txttable union 
    select col4 from txttable union 
    select col5 from txttable )
    a where col is not null/*
    数字          个数
    ----------- -----------
    1           2
    3           1
    5           1
    10          2
    12          3
    17          2
    20          2
    25          1
    30          1
    33          1
    34          1
    36          2
    40          2
    43          1
    45          4
    55          1
    56          1
    58          1
    68          1
    69          2
    89          1
    */