我有多个我试图集成的 sql 语句:
1 -
SELECT b.name, b.address, b.city, b.state, b.zip
FROM b
WHERE b.my_ID = '8'
2 -
SELECT DISTINCT room.room_ID, room.number, room.maxStudents
FROM room
WHERE room.building_ID =
(SELECT building_ID
FROM building
WHERE my_ID = '8')
我希望将第一条语句嵌入到选择字段中,例如:
SELECT DISTINCT room.room_ID, room.number, room.maxStudents,
(SELECT b.name, b.address, b.city, b.state, b.zip
FROM b
WHERE b.my_ID = '8')
FROM room
WHERE room.building_ID =
(SELECT building_ID
FROM building
WHERE my_ID = '8')
ROOM 表与 b 相关 - 每个房间都有一个字段 room.b_ID,例如:
room.b_ID = b.b_ID
我曾尝试在几个地方将其添加到综合声明中,但均未成功。
我想以所有房间和 room.fields 以及相关字段的列表结束,或者父母的字段 b.fields (b.name, b.address, b.city, b.state, b.zip )。b 是建筑。所以每个房间都有它所在的建筑物。我想要一份所有房间及其相关建筑物的列表。每栋建筑都会有不止一个房间,所以我知道结果中会有重复的数据。理想情况下,我想要一个 BUILDING 记录,然后该建筑物中的房间如下所示:
Building 1: Address, city,state,zip
<tab/null>room.name, room.maxstudents,...
<tab/null>room.name, room.maxstudents,...
<tab/null>room.name, room.maxstudents,...
Building 2: Address, city,state,zip
<tab/null>room.name, room.maxstudents,...
<tab/null>room.name, room.maxstudents,...
非常感谢任何帮助或指导!