比如表A有字段 单号 和 是否合格(0,1)
比如数据
001,0
001,1
001,0
002,1
002,1
003,0
003,1我要找出都合格的单号。请问怎么写呢
比如数据
001,0
001,1
001,0
002,1
002,1
003,0
003,1我要找出都合格的单号。请问怎么写呢
解决方案 »
- SQL2005打开表后不能直接修改记录?
- 如何实现二行的交差表?
- 大家来看看!
- 怎麼用存儲過程實現不定表不定條件的查詢
- 找寻英语词汇库
- 请问如何将一个表从竖着转换成横的?
- join问题!各位请帮我看看!谢谢啊!
- 如何进行数据库表设计,如何进行E-R设计,请帮助推荐一些书籍资料,
- sql2005下备份出来的,再还行到另外台脑的SQL2005上却报如下错误......
- 我想在asp里统计出sqlserver中某个数据库的大小及各表的大小,不知道命令
- 在线求解决sql pretty printer复制汉字是乱码
- sql server 20005 access 打开后 不使用 出现类似TCPIP #10054错误
select 单号 from A where 是否合格=0
insert into @tb select '001',0 union all
select '001',1 union all
select '002',1 union all
select '002',1 union all
select '003',1 union all
select '003',0select billno from @tb except select billno from @tb where flag=0/*
billno
002
*/
我这里用的2000,显示语法错误。
insert into @tb select '001',0 union all
select '001',1 union all
select '002',1 union all
select '002',1 union all
select '003',1 union all
select '003',0select DISTINCT billno from @tb WHERE billno NOT IN ( select billno from @tb where flag=0)/*
billno
002
*/---SQL 2000 上面的应该可以用
--数据量超过10万级以上使用下面的写法
declare @tb table( billno varchar(32),flag bit)
insert into @tb select '001',0 union all
select '001',1 union all
select '002',1 union all
select '002',1 union all
select '003',1 union all
select '003',0select DISTINCT billno from @tb a WHERE NOT exists ( select billno from @tb where billno =a.billno and flag=0)/*
billno
002
*/
(
col1 varchar(3),
col2 int
)
insert into t1
select '001',0 union all
select '001',1 union all
select '001',0 union all
select '002',1 union all
select '002',1 union all
select '003',0 union all
select '003',1
select * from t1select col1,SUM(col2) as col2 from t1 group by col1 having COUNT(col1)=SUM(col2)------------------------
col1 col2
002 2MSSQL2000及以上版本都可以。