GIVEN:大数据库(15GB
)。 10个表中有数百万行
任务:从3个表(table_a, table_b, table_c
)中检索信息。
表格通过
Foreign_Keys table_c<-table_b->table_a
(table_b has foreign keys for other tables)
table_b
为table_a中的每一行提供了多个序列(部分)。
Table_c
具有table_b
中每个序列的名称。
结果应该是:
---------------------------------------------------------------------
| table_a.id | table_c.firstsequence | table_c.LASTsequence |
---------------------------------------------------------------------
我的查询
SELECT
a.id, c.sequence_name,
(SELECT z.sequence_id FROM table_b as z WHERE z.a_fk_id = a.id
order by z.sequence_order desc limit 1) as last_sequence
FROM table_a AS a
JOIN table_b AS b ON a.id = b.a_fk_id
JOIN table_c AS c ON c.id = b.s_fk_id
WHERE
b.sequence_order = 1
ORDER BY a.id ASC
但是mysql
服务器才停止。它被暂停了。没有错误。
谢谢你的想法。
PS。这是真正的查询只是表和列的名称不同。