sql过滤查询问题,在线等。。。。顶者有分。。。请大家帮我看看。。。。

fengyuananan 2011-11-30 05:02:31
select id,underid,jhwgtime from fb_clunderinfo
得到的结果是:
id xdno day
185 0000000A29-201111280520-1006 0
186 0000000A29-201111280520-1006 21
187 0000000A29-201111280520-1006 0
188 0000000A29-201111280520-1006 0
189 0000000A34-201111280521-988 45
190 0000000A34-201111280521-988 0
191 0000000A34-201111280521-988 0
192 0000000A31-201111280522-1036 37
193 0000000A31-201111280522-1036 23
194 0000000A31-201111280522-1036 0
195 0000000A33-201111280523-988 0
196 0000000A33-201111280523-988 0
197 0000000A33-201111280523-988 0
198 0000000A32-201111280524-1036 9
199 0000000A32-201111280524-1036 10

我现在需要查询出来的数据是:0000000A32-201111280524-1036(存在两条数据,两条数据的day都不等于0)

规则是:要检索每一项的day不等于0的xdno。。。。。

问题解决,立刻结贴,,请牛人帮忙。。。
...全文
67 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2011-11-30
  • 打赏
  • 举报
回复
use Tempdb
go
--> -->

if not object_id(N'fb_clunderinfo') is null
drop table fb_clunderinfo
Go
Create table fb_clunderinfo([id] int,[xdno] nvarchar(28),[day] int)
Insert fb_clunderinfo
select 185,N'0000000A29-201111280520-1006',0 union all
select 186,N'0000000A29-201111280520-1006',21 union all
select 187,N'0000000A29-201111280520-1006',0 union all
select 188,N'0000000A29-201111280520-1006',0 union all
select 189,N'0000000A34-201111280521-988',45 union all
select 190,N'0000000A34-201111280521-988',0 union all
select 191,N'0000000A34-201111280521-988',0 union all
select 192,N'0000000A31-201111280522-1036',37 union all
select 193,N'0000000A31-201111280522-1036',23 union all
select 194,N'0000000A31-201111280522-1036',0 union all
select 195,N'0000000A33-201111280523-988',0 union all
select 196,N'0000000A33-201111280523-988',0 union all
select 197,N'0000000A33-201111280523-988',0 union all
select 198,N'0000000A32-201111280524-1036',9 union all
select 199,N'0000000A32-201111280524-1036',10
Go

SELECT * FROM fb_clunderinfo AS a WHERE [day]>0 AND EXISTS(SELECT * FROM fb_clunderinfo WHERE [xdno]=a.[xdno] HAVING COUNT(DISTINCT SIGN([day]))=1)
/*
id xdno day
198 0000000A32-201111280524-1036 9
199 0000000A32-201111280524-1036 10
*/
fengyuananan 2011-11-30
  • 打赏
  • 举报
回复
谢谢各位的热心帮助,问题解决了,,,

非常感谢!
  • 打赏
  • 举报
回复

select t1.* from
(select id,xdno ,day,count(xdno) as c_no
from fb_clunderinfo
where day<>0
group by xdno ) t1
where c_no=(select count(xdno) from fb_clunderinfo a where a.xdno=t1.xdno group by xdno)
AcHerat 元老 2011-11-30
  • 打赏
  • 举报
回复

create table fb_clunderinfo([id] int,[xdno] nvarchar(28),[day] int)
insert fb_clunderinfo
select 185,N'0000000a29-201111280520-1006',0 union all
select 186,N'0000000a29-201111280520-1006',21 union all
select 187,N'0000000a29-201111280520-1006',0 union all
select 188,N'0000000a29-201111280520-1006',0 union all
select 189,N'0000000a34-201111280521-988',45 union all
select 190,N'0000000a34-201111280521-988',0 union all
select 191,N'0000000a34-201111280521-988',0 union all
select 192,N'0000000a31-201111280522-1036',37 union all
select 193,N'0000000a31-201111280522-1036',23 union all
select 194,N'0000000a31-201111280522-1036',0 union all
select 195,N'0000000a33-201111280523-988',0 union all
select 196,N'0000000a33-201111280523-988',0 union all
select 197,N'0000000a33-201111280523-988',0 union all
select 198,N'0000000a32-201111280524-1036',9 union all
select 199,N'0000000a32-201111280524-1036',10
go

select [id],[xdno],[day]
from fb_clunderinfo t
where not exists (select 1 from fb_clunderinfo where xdno=t.xdno and [day]=0)

drop table fb_clunderinfo

/*********************

id xdno day
----------- ---------------------------- -----------
198 0000000a32-201111280524-1036 9
199 0000000a32-201111280524-1036 10

(2 行受影响)
AcHerat 元老 2011-11-30
  • 打赏
  • 举报
回复

select id,underid,jhwgtime
from fb_clunderinfo t
where not exists (select 1 from fb_clunderinfo where xdno=t.xdno and [day]=0)
中国风 2011-11-30
  • 打赏
  • 举报
回复
use Tempdb
go
--> -->

if not object_id(N'fb_clunderinfo') is null
drop table fb_clunderinfo
Go
Create table fb_clunderinfo([id] int,[xdno] nvarchar(28),[day] int)
Insert fb_clunderinfo
select 185,N'0000000A29-201111280520-1006',0 union all
select 186,N'0000000A29-201111280520-1006',21 union all
select 187,N'0000000A29-201111280520-1006',0 union all
select 188,N'0000000A29-201111280520-1006',0 union all
select 189,N'0000000A34-201111280521-988',45 union all
select 190,N'0000000A34-201111280521-988',0 union all
select 191,N'0000000A34-201111280521-988',0 union all
select 192,N'0000000A31-201111280522-1036',37 union all
select 193,N'0000000A31-201111280522-1036',23 union all
select 194,N'0000000A31-201111280522-1036',0 union all
select 195,N'0000000A33-201111280523-988',0 union all
select 196,N'0000000A33-201111280523-988',0 union all
select 197,N'0000000A33-201111280523-988',0 union all
select 198,N'0000000A32-201111280524-1036',9 union all
select 199,N'0000000A32-201111280524-1036',10
Go


select id,[xdno],[day] from fb_clunderinfo AS a WHERE EXISTS(SELECT 1 FROM fb_clunderinfo WHERE [xdno]=a.[xdno] AND id<>a.id AND [day]>0) AND [DAY]>0

/*
id xdno day
192 0000000A31-201111280522-1036 37
193 0000000A31-201111280522-1036 23
198 0000000A32-201111280524-1036 9
199 0000000A32-201111280524-1036 10
*/
中国风 2011-11-30
  • 打赏
  • 举报
回复

select id,[xdno],[day] from fb_clunderinfo AS a WHERE EXISTS(SELECT 1 FROM fb_clunderinfo WHERE [xdno]=a.[xdno] AND id<>a.id AND [day]>0) AND [DAY]>0

/*
id xdno day
192 0000000A31-201111280522-1036 37
193 0000000A31-201111280522-1036 23
198 0000000A32-201111280524-1036 9
199 0000000A32-201111280524-1036 10
*/
快溜 2011-11-30
  • 打赏
  • 举报
回复
select * from tb a
where not exists(select 1 from tb where xdno=a.xdno and day=0)
中国风 2011-11-30
  • 打赏
  • 举报
回复
select id,underid,jhwgtime from fb_clunderinfo AS a WHERE EXISTS(SELECT 1 FROM fb_clunderinfo WHERE underid=a.underid AND id=<>a.id AND [day]>0) AND [DAY]>0

34,590

社区成员

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

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