我有2个表,我正在尝试在mySQL查询上输出最有效的表JOIN。
表1:qa_framework_activities
id | activity
+--|-------------------
1 | text
2 | more text
3 | even more text
4 | more andmore text
5 | blah blah
6 | blah blah
和......
表2:qa_framework_indicators
id | pid | indicators | chrono
+---|-----+-------------------------------+--------
1 | 2 | text blah blayh | 1
2 | 2 | more text blah | 4
3 | 3 | even more text lipsum | 3
4 | 6 | more andmore text lipsum blah | 6
pid =父ID(第一个表中的id)
因此推测的mySQL查询将是:
SELECT
qa_framework_activities.id,
qa_framework_indicators.id
FROM
qa_framework_activities,
qa_framework_indicators
WHERE
qa_framework_activities.id = qa_framework_indicators.pid
我遇到的问题是如何最有效地显示按Chrono列中的Chrono值排序的结果(按qa_framework_activities.activity分组的qa_framework_indicators.indicators),如下表所示 - 6列中的任何一列?< / p>
我想根据chrono table 2列输出上述数据(chrono值为1 - 6)
所以最终结果如下:
Chrono 1 | Chrono 2 | Chrono 3 | Chrono 4 | Chrono 5 | Chrono 6 |
+----------|-------------|-------------|-------------|-------------|-------------|
Activity | Activity | Activity | Activity | Activity | Activity |
indicator | indicator | indicator | indicator | indicator | indicator |
indicator | | | | | |