sql可以这样写吗? select * from tb where not exists((select count(id) from tb)<1)后面查出的结果进行比较??可以实现这样的语句不?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不行是肯定的,用having可以比较好的解决。 NO 应该返回整个tb你想查什么 我的意思是这样 有字段表示性别 select 1 from tb where not exists((select count(id) from tb where xb='雄性') !=1) 雄性只能一只 多或者没有就不符合条件 试试看!select * from tb where not exists (select count(id) as id from tb where id<1) 不可以那样写:select * form tb t where (select count(1) from tb where xb=t.xb)=1 用这个试下select id from tb where xb= '雄性 ' group by idhaving count(id)<1 写在having 的 count是计算ID select count(id)是有区别的! declare @T table (id int, xb char(4))insert @T select 1,'雌性'insert @T select 2,'雄性'insert @T select 3,'雄性'insert @T select 3,'雌性'insert @T select 3,'雌性'insert @T select 4,'雄性'insert @T select 4,'雄性'insert @T select 4,'雌性'--雄性只能一只 多或者没有就不符合条件select * from @T a where (select count(id) from @T where id=a.id and xb='雄性')=1/*2 雄性3 雄性3 雌性3 雌性*/--并且最少要有一个雌性select * from @T a where (select count(id) from @T where id=a.id and xb='雄性')=1 and exists (select 1 from @T where id=a.id and xb='雌性')/*3 雄性3 雌性3 雌性*/ 关键是要了解sql的执行顺序,就像了解加减乘除一样 问一个菜鸟问题 为什么它说我的SQL SERVER不存在或者无访问权限? 请把这条sql语句转换成sqlserver的 对一张更换单的数据库设计 datetime数据类型 求助!如何实现以下查询? 具体时间(不是日期)如何比较??急,在线等待! 刚才的贴还有问题,再送100分好了 怎么在程序中设置ConnectionString? 为什么在存储过程中这样写出错? 请问union 与 order by newid() 的联合使用问题 还原问题.
select 1 from tb where not exists((select count(id) from tb where xb='雄性') !=1) 雄性只能一只 多或者没有就不符合条件
select * from tb where not exists (select count(id) as id from tb where id<1)
select * form tb t where (select count(1) from tb where xb=t.xb)=1
用这个试下
select id from tb where xb= '雄性 ' group by id
having count(id)<1
insert @T select 1,'雌性'
insert @T select 2,'雄性'
insert @T select 3,'雄性'
insert @T select 3,'雌性'
insert @T select 3,'雌性'
insert @T select 4,'雄性'
insert @T select 4,'雄性'
insert @T select 4,'雌性'--雄性只能一只 多或者没有就不符合条件
select * from @T a
where
(select count(id) from @T where id=a.id and xb='雄性')=1
/*
2 雄性
3 雄性
3 雌性
3 雌性
*/--并且最少要有一个雌性
select * from @T a
where
(select count(id) from @T where id=a.id and xb='雄性')=1
and exists (select 1 from @T where id=a.id and xb='雌性')
/*
3 雄性
3 雌性
3 雌性
*/