if (select x from tb where kind=1 and kindid =57)=(select x from tb where kind=251 and kindid =1) and (select y from tb where kind=1 and kindid =57)=(select y from tb where kind=251 and kindid =1)print 'x、y都相等'
create table test(id int,x int,y int,kind int,kindid int) insert test select 5,500,500,1,57 union all select 9,500,500,251,1 go--1代表相等 0代表不等select count(*) from test where x=y and kind = 1 and kindid = 57 ----------- 1(所影响的行数为 1 行)
if exists(select * from tb t where exists(select 1 from tb where kind=251 and kindid =1 and x=t.x an y=t.y)and kind=1 and kindid =57) print 'x、y都相等'
declare @t table(id int,x int,y int,kind int,kindid int) insert @t select 5,500,500,1,57 union all select 9,500,500,251,1 if exists(select * from @t t where exists(select 1 from @t where kind=251 and kindid =1 and x=t.x and y=t.y)and kind=1 and kindid =57) print 'x、y都相等'else print 'x、y不相等'---------------------------x、y都相等
IF EXISTS ( (select x from location where kind=1 and kindid=57) = (select x from location where kind=251 and kindid=1) and (select y from location where kind=1 and kindid=57) = (select y from location where kind=251 and kindid=1) )非常感谢: js_szy,明天我到单位去测试一下.可以后马上给份哈
declare @t table(id int,x int,y int,kind int,kindid int) insert @t select 5,500,500,1,57 union all select 9,400,500,251,1 ----修改X为400,不一样了 if exists(select * from @t t where exists(select 1 from @t where kind=251 and kindid =1 and x=t.x and y=t.y)and kind=1 and kindid =57) print 'x、y都相等'else print 'x、y不相等'---------------------------x、y不相等
if OBJECT_ID('tb') is not null drop table tb create table tb(id int,x int,y int,kind int,kindid int) insert tb select 5,500,500,1,57 union all select 9,500,500,251,1 go if exists(select * from tb t where exists(select 1 from tb where kind=251 and kindid =1 and x=t.x and y=t.y) and kind=1 and kindid =57) print 'x、y都相等' else print 'x,y不等
用CASE WHEN 就可以了!
if OBJECT_ID('tb') is not null drop table tb create table tb(id int,x int,y int,kind int,kindid int) insert tb select 5,500,500,1,57 union all select 9,500,500,251,1 goif exists(select 1 from tb a where x=y and (kind=251 and kindid =1) or (kind=1 and kindid=57)) print 'x、y都相等' else print 'x,y不等' --x、y都相等最简单的方法!呵呵!
不用exists的话,1楼的可以一定要用exists的话。6楼或者8楼的都可以
DECLARE @t TABLE(id INT,x INT,y INT,kind INT,kindid INT) INSERT @t SELECT 5,500,500,1,57 UNION ALL SELECT 9,500,500,251,1IF EXISTS(SELECT * FROM @t A INNER JOIN @t B ON A.x = B.x AND A.y = B.y WHERE A.kind = 1 AND A.kindid = 57 AND B.kind = 251 AND B.kindid = 1) PRINT 'x、y都相等'ELSE PRINT 'x、y不相等'
id x y kind kindid ----------------------- 5 400 500 6 57 9 400 500 251 1
感觉这样可以,感谢大家了.if exists (select * from location t where exists(select 1 from location where kind=251 and kindid=1 and x=t.x and y=t.y) and kind=1 and kindid=57)
if (select x from tb where kind=1 and kindid =57)=(select x from tb where kind=251 and kindid =1) and (select y from tb where kind=1 and kindid =57)=(select y from tb where kind=251 and kindid =1)print 'x、y都相等'
create table test(id int,x int,y int,kind int,kindid int)
insert test
select 5,500,500,1,57 union all
select 9,500,500,251,1
go--1代表相等 0代表不等select count(*) from test
where x=y and kind = 1 and kindid = 57
-----------
1(所影响的行数为 1 行)
if exists(select * from tb t where exists(select 1 from tb where kind=251 and kindid =1 and x=t.x an y=t.y)and kind=1 and kindid =57)
print 'x、y都相等'
declare @t table(id int,x int,y int,kind int,kindid int)
insert @t
select 5,500,500,1,57 union all
select 9,500,500,251,1
if exists(select * from @t t where exists(select 1 from @t where kind=251 and kindid =1 and x=t.x and y=t.y)and kind=1 and kindid =57) print 'x、y都相等'else
print 'x、y不相等'---------------------------x、y都相等
(
(select x from location where kind=1 and kindid=57) = (select x from location where kind=251 and kindid=1)
and
(select y from location where kind=1 and kindid=57) = (select y from location where kind=251 and kindid=1)
)非常感谢:
js_szy,明天我到单位去测试一下.可以后马上给份哈
declare @t table(id int,x int,y int,kind int,kindid int)
insert @t
select 5,500,500,1,57 union all
select 9,400,500,251,1 ----修改X为400,不一样了
if exists(select * from @t t where exists(select 1 from @t where kind=251 and kindid =1 and x=t.x and y=t.y)and kind=1 and kindid =57) print 'x、y都相等'else
print 'x、y不相等'---------------------------x、y不相等
create table tb(id int,x int,y int,kind int,kindid int)
insert tb
select 5,500,500,1,57 union all
select 9,500,500,251,1
go
if exists(select * from tb t where
exists(select 1 from tb where kind=251 and kindid =1 and x=t.x and y=t.y) and kind=1 and kindid =57)
print 'x、y都相等'
else
print 'x,y不等
create table tb(id int,x int,y int,kind int,kindid int)
insert tb
select 5,500,500,1,57 union all
select 9,500,500,251,1
goif exists(select 1 from tb a where x=y and (kind=251 and kindid =1) or (kind=1 and kindid=57))
print 'x、y都相等'
else
print 'x,y不等'
--x、y都相等最简单的方法!呵呵!
不用exists的话,1楼的可以一定要用exists的话。6楼或者8楼的都可以
DECLARE @t TABLE(id INT,x INT,y INT,kind INT,kindid INT)
INSERT @t
SELECT 5,500,500,1,57 UNION ALL
SELECT 9,500,500,251,1IF EXISTS(SELECT * FROM @t A
INNER JOIN @t B ON A.x = B.x AND A.y = B.y
WHERE A.kind = 1 AND A.kindid = 57
AND B.kind = 251 AND B.kindid = 1) PRINT 'x、y都相等'ELSE
PRINT 'x、y不相等'
-----------------------
5 400 500 6 57
9 400 500 251 1
(select * from location t where exists(select 1 from location where kind=251 and kindid=1 and x=t.x and y=t.y) and kind=1 and kindid=57)