0

我有三个这样的表:

table_a:
id    time   name
a_1   2:30   Joe
a_2   2:35   Mike

table_b:
id    time   name
b_1   3:30   Tim
b_2   5:35   Molly

table_c:
id    tag
a_1   cats
b_1   dogs
b_2   bats
a_2   mats

他们加入了类似的东西: -

SELECT *  FROM table_a  
JOIN table_c ON table_a.id = table_c.id  
JOIN table_b ON table_b.id = table_c.id

我希望能够按时间订购 table_a 的所有同意,但也订购 table_b。这样,当它显示时一切都井井有条,我怎么能告诉它在各自的时间订购某些东西?

4

2 回答 2

1

最后打一个 ORDER BY。SELECT 是该语句的最外层运算符。

SELECT * FROM (table_a JOIN table_c ON table_a.id = table_c.id JOIN table_b ON table_b.id = table_c.id) ORDER BY table_a.time, table_b.time
于 2013-07-12T20:43:16.450 回答
0

您是指一个订单内另一个订单吗?

如果是这样

SELECT *  
FROM table_a  
JOIN table_c ON table_a.id = table_c.id  
JOIN table_b ON table_b.id = table_c.id
ORDER BY table_a.time, table_b.time
于 2013-07-12T20:43:32.577 回答