列如
a  b (列名)
1  2
2  3
1  4
8  2
19 11
....
要求:查询出两列中不同值的总数
例子:
a b 
s a
a x
结果为3

解决方案 »

  1.   

    全部用SQL可以实现吗?不考虑代码??
      

  2.   

    可以的,
    SELECT 第一列 AS '个数'
    FROM 表名
    UNION
    SELECT 第二列
    FROM 表名
    ORDER BY '个数'
    COMPUTE COUNT(第一列)
      

  3.   

    那样会把
    a b 
    s a
    a x
    变成结果为4
      

  4.   

    select count(distinct a)
    from
    (
    select a from table
    union all
    select b from table
    ) c
      

  5.   

    leaohong(无定河)  
     
       select count(distinct a)
    from
    (
    select a from table
    union all
    select b from table
    ) c