也就是说:
id      a         b       c        d          e
1 1 3 4 6 NULL
2 2 3 4 NULL NULL
3 1 2 3 NULL NULL
4 2 6 NULL NULL NULL
5 2 3 4 5 NULL
6 2 3 5 NULL NULL
7 1 2 3 4 6
8 1 3 4 5 6
9 1 NULL NULL NULL NULL
是一个表,表名是shiyan。id   a   b    c
1    1   3    4 
2    1   3    6 
3    1   4    6 
4    2   3    4 
5    3   4    6 
也是一个表,表名是SHIYAN,要求统计出SHIYAN中每一行的是不在shiyan中有,如果有,就加一,还是以1 3 4为例,看看它是不是在shiyan表中的每一行都存在,只要某一行存在,计数就加一,不用考虑1 3 4 在shiyan中个行的顺序,只要有就行。1 3 4与shiyan中的第一行比较,然后与第二行比较,...,一直到第九行为之,总共有3次,接下来1 3 6 与shiyan中的第一行比较,然后第二行,...,一直到第九行,依次类推
结果是:
id  a   b   c  个数
1   1   3   4   3
2   1   3   6   3
3   1   4   6   3
4   2   3   4   3
5   3   4   6   3请高手帮忙,小弟非常感谢!

解决方案 »

  1.   

    id      a         b       c        d          e
    1       1         3       4        6         NULL
    2       2         3       4        NULL      NULL
    3       1         2       3        NULL      NULL
    4       2         6       NULL     NULL      NULL
    5       2         3       4         5        NULL
    6       2         3       5        NULL      NULL
    7       1         2       3         4         6
    8       1         3       4         5         6
    9       1       NULL      NULL     NULL    NULL
    是一个表,表名是shiyan。id   a   b    c
    1    1   3    4 
    2    1   3    6 
    3    1   4    6 
    4    2   3    4 
    5    3   4    6 
    也是一个表,表名是SHIYAN,要求统计出SHIYAN中每一行的是不在shiyan中有,如果有,就加一,还是以1 3 4为例,看看它是不是在shiyan表中的每一行都存在,只要某一行存在,计数就加一,不用考虑1 3 4 在shiyan中个行的顺序,只要有就行。1 3 4与shiyan中的第一行比较,然后与第二行比较,...,一直到第九行为之,总共有3次,接下来1 3 6 与shiyan中的第一行比较,然后第二行,...,一直到第九行,依次类推
    结果是:
    id  a   b   c  个数
    1   1   3   4   3
    2   1   3   6   3
    3   1   4   6   3
    4   2   3   4   3
    5   3   4   6   3
      

  2.   

    --呵呵,又是我
    declare @shiyan1 table(id int,  a int,  b int,c int, d int,  e int)
    insert @shiyan1 select 1,1,  3,4, 6,  NULL
    union all select 2,2,  3,4, NULL,  NULL
    union all select 3,1,  2,3, NULL,  NULL
    union all select 4,2,  6,NULL, NULL,  NULL
    union all select 5,2,  3,4,  5, NULL
    union all select 6,2,  3,5, NULL,  NULL
    union all select 7,1,  2,3,  4,  6
    union all select 8,1,  3,4,  5,  6
    union all select 9,1,NULL,  NULL, NULL,NULLdeclare @shiyan2 table(id int,   a int,   b int,c int)
    insert @shiyan2 select 1,1  , 3,4 
    union all select 2,1 ,  3,6 
    union all select 3,1,   4,6 
    union all select 4,2 ,  3,4 
    union all select 5,3  , 4,6 --select * from @shiyan1
    --select * from @shiyan2select *,
    (select count(*) from @shiyan1 where  (t.a=a or t.a=b or t.a=c or t.a=d or t.a=e) and 
    (t.b=a or t.b=b or t.b=c or t.b=d or t.b=e) and
    (t.c=a or t.c=b or t.c=c or t.c=d or t.c=e)
    ) 个数 
    from @shiyan2 t--结果
    id          a           b           c           个数          
    ----------- ----------- ----------- ----------- ----------- 
    1           1           3           4           3
    2           1           3           6           3
    3           1           4           6           3
    4           2           3           4           3
    5           3           4           6           3(所影响的行数为 5 行)
      

  3.   

    create table A(id int, a int, b int, c int, d int, e int)
    insert A select 1,       1,         3,       4,        6,         NULL
    union all select 2,       2,         3,       4,        NULL,      NULL
    union all select 3,       1,         2,       3,        NULL,      NULL
    union all select 4,       2,         6,       NULL,     NULL,      NULL
    union all select 5,       2,         3,       4,         5,        NULL
    union all select 6,       2,         3,       5,        NULL,      NULL
    union all select 7,       1,         2,      3,         4,         6
    union all select 8,       1,         3,       4,         5,         6
    union all select 9,       1,       NULL,      NULL,     NULL,    NULLcreate table B(id int, a int, b int, c int)
    insert B select 1,    1,   3,    4 
    union all select 2,    1,   3,    6 
    union all select 3,    1,   4,    6 
    union all select 4,    2,   3,    4 
    union all select 5,    3,   4,    6 select *,
    num=(select sum(num) from 
    (
    select 
    num =
    (select count(distinct a) from 
    (select a union all select b union all select c union all select d union all select e) tmpA 
     where tmpA.a in(B.a, B.b, B.c)) / 3
    from A
    ) tmp)
    from B
    --result
    id          a           b           c           num         
    ----------- ----------- ----------- ----------- ----------- 
    1           1           3           4           3
    2           1           3           6           3
    3           1           4           6           3
    4           2           3           4           3
    5           3           4           6           3(5 row(s) affected)