sql 语句查询一个表中不同的记录有多少条?例如:表明 T  字段 id  adress    最好是能在sql和oracle下通用的句子谢谢 

解决方案 »

  1.   

    oracle:
    select count(distinct id||adress) form tb;sqlserver:
    select count(distinct id+adress) form tb;
      

  2.   

    select count(distinct id,adress) from T
      

  3.   

    统计单个字段的非重复记录条数:
    select count(distinct id) from t
    统计多个字段的非重复记录条数:
    SELECT COUNT(*) FROM(select count(distinct id,adress) from t)
    统计所有字段的非重复记录条数:
    select count(distinct *) from t
      

  4.   

    这样是不行的 会报错
    ORA-00909: invalid number of arguments
      

  5.   

    SQL> select * from t4;       ID1        ID2
    ---------- ----------
             1          2
             1          3
             1          2
    --查看某一列不同的记录数
    SQL> select count(distinct id1) from t4;COUNT(DISTINCTID1)
    ------------------
                     1SQL> select count(distinct id2) from t4;COUNT(DISTINCTID2)
    ------------------
                     2
    --查看表中各列不同记录数
    SQL> select count(distinct id1||id2) from t4;COUNT(DISTINCTID1||ID2)
    -----------------------
                          2