我需要从表 A、表 A 中的 8 行中获取值,并使用表 A 中每一行中的 id,从表 B 和表 C 中获取数据,并将这些数据存储在一个数组中。
这就是我的意思:
Select id, name from table A --This returns 8 rows, which is the base table.
Select rate, review from table B --this returns 5 rows, and i store this 5 rows in an array and i append it to first row in table A
Select rate, review from table C --this returns 5 rows, and i store this 5 rows in an array and i append it to first row in table A
所以基本上,我正在做一个请求,需要从两个不同的表中获取行,并将其添加到该基表的第一行,因为我制作了 8 行基表。
这是我将它作为 json 数据返回时的样子:
"Rows": {
"Rows0": {
"ID": "524",
"Name": "Value 1",
"reviews": {
"name": "review for row value 0",
"timing": [
{
"day": "Sunday",
"Timing": "5:00PM"
},
{
"day": "Monday",
"Timing": "5:00PM"
},
{
"day": "Tuesday",
"Timing": "5:00PM"
}
],
"day_showing": "Tuesday",
"recordid": "54570",
}
},
"Rows1": {
"ID": "789",
"Name": "Value 1",
"reviews": {
"name": "review for row value 1",
"timing": [
{
"day": "Sunday",
"Timing": "5:00PM"
},
{
"day": "Monday",
"Timing": "5:00PM"
},
{
"day": "Tuesday",
"Timing": "5:00PM"
}
],
"day_showing": "Tuesday",
"recordid": "54570",
}
}
.....and more rows
有没有办法让我使用连接,并在内部将这三个表连接在一起。这样我就不必遍历每一行并附加两个表,因为这段代码效率低下,因为我返回第一行,就像 8 个不同的一样,8 行被附加到第一行并作为来自两个不同的数组返回表。我需要有人帮助阐明这一点。我正在寻找最好的 SQL 代码构造,谢谢。