字段1 字段2
36 0
36 0
36 0
36 78
36 78
36 78
36 43要求SQL语句把 字段2 不等于0的重复记录过滤输出。如果如下:字段1 字段2
36 0
36 0
36 0
36 78
36 43
36 0
36 0
36 0
36 78
36 78
36 78
36 43要求SQL语句把 字段2 不等于0的重复记录过滤输出。如果如下:字段1 字段2
36 0
36 0
36 0
36 78
36 43
解决方案 »
- 高级查询求教????
- Sql Server 2005内存占用过大,如何解决?
- 截取字符串的问题
- 简单问题.抢分来..convert问题
- 表已经删除依然提示该表还在做复制
- 存储过程的表名是不确定的,能不能用字符串拼接啊
- 借贷余实现方法,高手请进,在线等
- 请教:我们用的sql server的查询分析器,为什么每次连接远程服务器的时候找不到自己的数据库(能连接),这是为什么
- 请教ref cursor的使用,使用out参数能否返回查询结果集?
- 谁知道哪里有ERwin下载么?(急需)
- SQL Web Data Administrator怎么用?
- sql server 2008升级到sql server 2008 R2吗
union all
select distinct * from tb where ziduan2=0
union all
select distinct * from tb where ziduan2!=0
declare @table table(字段1 int,字段2 int)
insert into @table
select 36 ,0 union all
select 36 ,0 union all
select 36 ,0 union all
select 36 ,78 union all
select 36 ,78 union all
select 36 ,78 union all
select 36 ,43select * from @table where 字段2=0
union all
select distinct * from @table where 字段2<>0字段1 字段2
----------- -----------
36 0
36 0
36 0
36 43
36 78(5 行受影响)
如果其它字段有不同的值,这个查询就无效了啊!
如:
字段1 字段2 字段3
123 36 0
456 36 0
789 36 66
654 36 66
fdd 36 78