日期:2014-05-18  浏览次数:20455 次

查询表B的数据怎么按照表A分页
现在的表结构是这样的:
酒店表:t_hotel
id                   序列
name               酒店名
city               城市
area               区
star               星级
房间表:t_room
id                   序列
hotelid         对应t_hotel的id
name               房间名称
price             价格
bunk               床位

现在搜索房间按照t_room分页的
1,[酒店名][房间名][价格]
2,[酒店名][房间名][价格]
3,[酒店名][房间名][价格]
这样同一个酒店里的房间满足检索条件的可能有多条记录,那[酒店名]就重复了

要怎么搜索房间才能按照酒店数量分页,而不是按照房间数量分页,象这样的效果
1,[酒店名]
      [房间名][价格]
2,[酒店名]
      [房间名][价格]
      [房间名][价格]
3,酒店名
      [房间名][价格]

------解决方案--------------------
不会,帮顶
------解决方案--------------------
不明白,表1跟表2什么关系??用什么关联??
------解决方案--------------------
select h.name,r.name,r.price from t_hotel h join t_room r
on h.id=r.hotelid order by h.name

至于你要的什么格式,用别的程序做。
------解决方案--------------------
create table t_hotel(id1 varchar(4),name1 varchar(20),city varchar(20),area varchar(10),star int)
insert into t_hotel
select 'A001 ', '奥林匹克大酒店 ', '温州 ', '华东区 ',5
union select 'B001 ', '金都大酒店 ', '长沙 ', '华南区 ',4
union select 'A002 ', '国贸大酒店 ', '长沙 ', '华南区 ',5
union select 'C001 ', '金茂皇冠大酒店 ', '温州 ', '华东区 ',3
union select 'B002 ', '国宾馆 ', '长春 ', '东北区 ',4
go

create table t_room(id1 varchar(4),hotelid varchar(4),name1 varchar(20),price varchar(10),bunk varchar(4))
insert into t_room
select '0001 ', 'A001 ', '808 ', '1500 ', '1-1 '
union select '0002 ', 'B001 ', '408 ', '800 ', '4-2 '
union select '0003 ', 'A002 ', '608 ', '1200 ', '6-3 '
union select '0004 ', 'C001 ', '108 ', '250 ', '2-4 '
union select '0005 ', 'B002 ', '308 ', '650 ', '3-1 '
union select '0006 ', 'A001 ', '708 ', '1400 ', '8-8 '
union select '0007 ', 'C001 ', '202 ', '150 ', '1-2 '
union select '0008 ', 'B002 ', '303 ', '560 ', '2-2 '
go


select distinct t_hotel.name1,t_room.name1,price from t_hotel,t_room
where t_hotel.id1=t_room.hotelid
group by t_hotel.name1
order by t_hotel.name1,t_room.price
------解决方案--------------------
楼上是错的
------解决方案--------------------
不太明白意思..
列个详细的结果出来还好做
------解决方案--------------------
use sql_test
go
create table t_hotel(id1 varchar(4),name1 varchar(20),city varchar(20),area varchar(10),star int)
insert into t_hotel
select 'A001 ', '奥林匹克大酒店 ', '温州 ', '华东区 ',5