SQL取不重复的值

xin84604585 2007-12-27 08:44:07
有个Name字段!
Name
张三
李四
NULL(没有值)
张三
张三
李四
NULL(没有值)
我想取出来的效果
Name
张三
李四
...全文
1500 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiule 2007-12-28
  • 打赏
  • 举报
回复
select distinct [name]
from @tb
where name <> ''
hui_hui_2007 2007-12-28
  • 打赏
  • 举报
回复
我要排除的是空格值不是null值!

----------------------------
难道你不会举一反三吗:

select distinct [name]
from @tb
where name <> ''
-狙击手- 2007-12-28
  • 打赏
  • 举报
回复
不好意思,没看到14楼已经 回了
-狙击手- 2007-12-28
  • 打赏
  • 举报
回复
declare @Tb table (name varchar(10))

insert into @tb
select '张三'
union all select null
union all select '张三'
union all select '李四'
union all select ''
union all select '张三'
union all select '李四'

select distinct [name]
from @tb
where isnull(name,'')<>''

/*


name
----------
李四
张三

(所影响的行数为 2 行)
*/

areswang 2007-12-28
  • 打赏
  • 举报
回复
select distinct [name]
from @tb
where isnull([name],'')<>''
xin84604585 2007-12-28
  • 打赏
  • 举报
回复
我要排除的是空格值不是null值!
parss 2007-12-27
  • 打赏
  • 举报
回复
select distincct name fromm 表
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复

declare @Tb table (name varchar(10))

insert into @tb
select 'aaa'
union all select null
union all select 'aaa'
union all select 'bb'
union all select null
union all select 'aaa'
union all select 'ccc'

--以下为对比
select distinct [name]
from @tb
/*
name
----------
NULL
aaa
bb
ccc

(所影响的行数为 4 行)
*/
select distinct [name]
from @tb
where name is not null
/*
name
----------
aaa
bb
ccc

(所影响的行数为 3 行)
*/
hui_hui_2007 2007-12-27
  • 打赏
  • 举报
回复

declare @Tb table (name varchar(10))

insert into @tb
select 'aaa'
union all select null
union all select 'aaa'
union all select 'bb'
union all select null
union all select 'aaa'
union all select 'ccc'

select distinct [name]
from @tb
where name is not null
xin84604585 2007-12-27
  • 打赏
  • 举报
回复
不行了!
Name
张三
李四
(没有值)
张三
张三
李四
(没有值)
我想取出来的效果
Name
张三
李四
什么也没有了,也没有null这个值了!
nicejane 2007-12-27
  • 打赏
  • 举报
回复
select distinct   [name]   from   tb    where   [name]   is   not   null
homel 2007-12-27
  • 打赏
  • 举报
回复
select distinct name from tb where name is not null
gggg007 2007-12-27
  • 打赏
  • 举报
回复
distinct [name] where [name] is not null
昵称被占用了 2007-12-27
  • 打赏
  • 举报
回复

select name from tb where name is not null group by name
leo_lesley 2007-12-27
  • 打赏
  • 举报
回复
select distinct [name] from 表
昵称被占用了 2007-12-27
  • 打赏
  • 举报
回复

select name from tb group by name
yiyi_wx 2007-12-27
  • 打赏
  • 举报
回复

Select distinct Name

dawugui 2007-12-27
  • 打赏
  • 举报
回复
select distinct name from tb where name is not null

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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