数据库的数据如果是:
字段 id a b c
0 钢笔 023 收到
0 铅笔 023 收到
0 圆珠笔 023 收到
0 圆珠笔 023 收到
0 钢笔 023 收到
0 铅笔 023 没有到
0 圆珠笔 023 没有到
0 圆珠笔 023 收到
2 钢笔 056 收到
2 铅笔 056 收到
3 圆珠笔 087 收到
3 圆珠笔 087 收到
字段a是货物名称,b是组号c 是收到情况
怎样来查询c字段等于"收到"的组号显示出来效果如下: id b
2 056
3 087
字段 id a b c
0 钢笔 023 收到
0 铅笔 023 收到
0 圆珠笔 023 收到
0 圆珠笔 023 收到
0 钢笔 023 收到
0 铅笔 023 没有到
0 圆珠笔 023 没有到
0 圆珠笔 023 收到
2 钢笔 056 收到
2 铅笔 056 收到
3 圆珠笔 087 收到
3 圆珠笔 087 收到
字段a是货物名称,b是组号c 是收到情况
怎样来查询c字段等于"收到"的组号显示出来效果如下: id b
2 056
3 087
from tb
where c='收到'
from tbl as a where not exists
(select * from tbl
where a.id=id and c='没有到')
where c='收到' and not exists(select 1 from tab where b=t.b and c='没有到')
from tbl as a where not exists
(select * from tbl
where a.id=id and c='没有到')
from tbl as a where not exists
(select * from tbl
where a.id=id and c='没有到')
好象不对的。查询出来却是2
我写个我的想法,select distinct id,b from tbl where b not in(select distinct b from tbl where c='没有收到')
declare @t table(id int,a varchar(100),b int,c varchar(100))
insert @t
select 0, '钢笔', 023, '收到'
union all select 0, '铅笔' , 023, ' 收到'
union all select 0, '圆珠笔', 023, ' 收到'
union all select 0, '圆珠笔', 023 , '收到'
union all select 0, '钢笔' , 023, '收到'
union all select 0, '铅笔' , 023, '没有到'
union all select 0, '圆珠笔', 023, '没有到'
union all select 0, '圆珠笔', 023, '收到'
union all select 2, '钢笔' , 056, '收到'
union all select 2, '铅笔' , 056, '收到'
union all select 3, '圆珠笔' , 087, '收到'
union all select 3, '圆珠笔', 087, '收到'
--计算查询出有多少条记录
select count(*) from @t
where c not in('没有到') and id not in(select id from @t where c='没有到')select distinct id,b from @t
where c not in('没有到') and id not in(select id from @t where c='没有到')