hotelb h id name train
1111111111 中国大酒店 1
2222222222 珠江大酒店 1
3333333333 年屁大酒店 2
roomb r
c_id stageprice 1111111111 300
1111111111 400
1111111111 600
2222222222 200
2222222222 300
2222222222 400 取h.train=1 结果是: h.c_id r.stageprice train 1111111111 300 1
2222222222 200 1
其中r.c_id应该是和h.id对应的,h表唯一,r有多个.求r.stageprice和h.*
1111111111 中国大酒店 1
2222222222 珠江大酒店 1
3333333333 年屁大酒店 2
roomb r
c_id stageprice 1111111111 300
1111111111 400
1111111111 600
2222222222 200
2222222222 300
2222222222 400 取h.train=1 结果是: h.c_id r.stageprice train 1111111111 300 1
2222222222 200 1
其中r.c_id应该是和h.id对应的,h表唯一,r有多个.求r.stageprice和h.*
insert into @a select 1,'中国大酒店',1
insert into @a select 2,'珠江大酒店',1
insert into @a select 3,'年屁大酒店',2
declare @b table (id int,train int)
insert into @b select 1,300
insert into @b select 1,400
insert into @b select 1,600
insert into @b select 2,200
insert into @b select 2,300
insert into @b select 2,400select b.train,a.* from @b b left join @a a on b.id=a.id [align=left]300 1 中国大酒店 1
400 1 中国大酒店 1
600 1 中国大酒店 1
200 2 珠江大酒店 1
300 2 珠江大酒店 1
400 2 珠江大酒店 1[/align]
from hotelb h, roomb r
where h.id = r.c_id
group by h.id,h.name,h.train
insert into @a select 1,'中国大酒店',1
insert into @a select 2,'珠江大酒店',1
insert into @a select 3,'年屁大酒店',2
declare @b table (id int,train int)
insert into @b select 1,300
insert into @b select 1,400
insert into @b select 1,600
insert into @b select 2,200
insert into @b select 2,300
insert into @b select 2,400
select cast(a.name as varchar ) name,a.train,b.train
from @a a
right join @b b on a.id= b.id
where not exists( select 1 from @b where b.id = id and train < b.train)/*name train train
------------------------------ ----------- -----------
中国大酒店 1 300
珠江大酒店 1 200(所影响的行数为 2 行)*/
declare @a table (id int,name varchar(8000),train int)
insert into @a select 1,'中国大酒店',1
insert into @a select 2,'珠江大酒店',1
insert into @a select 3,'年屁大酒店',2
declare @b table (id int,train int)
insert into @b select 1,300
insert into @b select 1,400
insert into @b select 1,600
insert into @b select 2,200
insert into @b select 2,300
insert into @b select 2,400select *
from
@a a
join
@b b on a.ID=b.ID
where
not exists(select 1 from @b where ID=b.ID and train<b.train)