sql 语句查询一个表中不同的记录有多少条?

yurui05 2009-12-11 02:27:09
sql 语句查询一个表中不同的记录有多少条?

例如:表明 T 字段 id adress

最好是能在sql和oracle下通用的句子

谢谢


...全文
369 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wh62592855 2009-12-11
  • 打赏
  • 举报
回复
SQL> select * from t4;

ID1 ID2
---------- ----------
1 2
1 3
1 2
--查看某一列不同的记录数
SQL> select count(distinct id1) from t4;

COUNT(DISTINCTID1)
------------------
1

SQL> select count(distinct id2) from t4;

COUNT(DISTINCTID2)
------------------
2
--查看表中各列不同记录数
SQL> select count(distinct id1||id2) from t4;

COUNT(DISTINCTID1||ID2)
-----------------------
2
wh62592855 2009-12-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yo_258 的回复:]
select count(distinct id,adress) from T

[/Quote]这样是不行的 会报错
ORA-00909: invalid number of arguments
yurui05 2009-12-11
  • 打赏
  • 举报
回复
一楼经典,巧妙
yo_258 2009-12-11
  • 打赏
  • 举报
回复
select count(distinct id,adress) from T
xuanxingmin 2009-12-11
  • 打赏
  • 举报
回复
统计单个字段的非重复记录条数:
select count(distinct id) from t
统计多个字段的非重复记录条数:
SELECT COUNT(*) FROM(select count(distinct id,adress) from t)
统计所有字段的非重复记录条数:
select count(distinct *) from t
liusong_china 2009-12-11
  • 打赏
  • 举报
回复
oracle:
select count(distinct id||adress) form tb;

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

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧