首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问大侠们,这样的查询能实现吗?

2011-12-29 
请教大侠们,这样的查询能实现吗???????????????表一A列A列000110001200013000140001500016000170001800019

请教大侠们,这样的查询能实现吗???????????????
表一
A列A列
00011
00012
00013
00014
00015
00016
00017
00018
00019
000110
000111
000112
000210
00031
00032
00033
00034
00035
00036
00037
00038
00039
000310
000311
000312
---------
想查询出上表中A列值 '0002 '和B列值 '10 '这一条记录,如何查询,谢谢!!!




[解决办法]
select
t.*
from
表一 t
where
not exists(select 1 from 表一 where A列=t.A列 and B列!=t.B列)
[解决办法]
declare @t table(A varchar(4),B int)
insert into @t select '0001 ',1
insert into @t select '0001 ',2
insert into @t select '0001 ',3
insert into @t select '0001 ',4
insert into @t select '0001 ',5
insert into @t select '0001 ',6
insert into @t select '0001 ',7
insert into @t select '0001 ',8
insert into @t select '0001 ',9
insert into @t select '0001 ',10
insert into @t select '0001 ',11
insert into @t select '0001 ',12
insert into @t select '0002 ',10
insert into @t select '0003 ',1
insert into @t select '0003 ',2
insert into @t select '0003 ',3
insert into @t select '0003 ',4
insert into @t select '0003 ',5
insert into @t select '0003 ',6
insert into @t select '0003 ',7
insert into @t select '0003 ',8
insert into @t select '0003 ',9
insert into @t select '0003 ',10
insert into @t select '0003 ',11
insert into @t select '0003 ',12

select t.* from @t t where not exists(select 1 from @t where A=t.A and B!=t.B)

/*
A B
---- -----------
0002 10
*/
[解决办法]
还是这样?
select A列,min(B列) from t group by A列 having count(*) = 1
[解决办法]
如果B列没有记录数时,只有通过临时表实现

select * ,id=identity(1,1) into #
from 表
update b
set id=(select count(*)from # where A列=b.A列 and id!> b.id)--生成记录数
from # b
查询
select * from # where A列 = '0002 ' and id = '10 '
[解决办法]
这样?
select * from t where A列 = '0002 ' and B列 <> '12 '
[解决办法]
--试试
update t _a
set B列 = 12
where exists(
select 1
from t
group by A列
having count(*) = 1
and min(B列) <> '12 '
and _a.A列 = A列
and _a.B列 = min(B列)
)

[解决办法]
郁闷在我发前问题已经解决了

那就揭贴吧!~

热点排行