我有一个这样的数据库结构:
•Insured
表
+-----------+--------------+-----+
| InsuredID | Name | ... |
+-----------+--------------+-----+
| 1 | John Doe | ... |
| 2 | Bill Gates | ... |
| 3 | Steve Jobs | ... |
+-----------+--------------+-----+
•Accompany
表
+-------------+-----------+---------------+-----+
| AccompanyID | InsuredID | Name | ... |
+-------------+-----------+---------------+-----+
| 1 | 1 | Joanna Doe | ... |
| 2 | 1 | Johnny Doe | ... |
| 3 | 3 | Steve Ballmer | ... |
+-------------+-----------+---------------+-----+
我怎样才能得到这个结果:
+----------------+-----+
| Name | ... |
+----------------+-----+
| John Doe | ... |
| Joanna Doe | ... |
| Johnny Doe | ... |
| Bill Gates | ... |
| Steve Jobs | ... |
| Steve Ballmer | ... |
+----------------+-----+
我怎样才能使查询的顺序为 -thenInsured
的Accompany
地方Accompany.InsuredID
相当于Insured.InsuredID
之前的Accompany
. 应该这样排序:
- John Doe(被保险人)
InsuredID = 1
- 乔安娜·多伊(伴奏)
InsuredID = 1
- 约翰尼·多伊(伴奏)
InsuredID = 1
- 比尔盖茨(被保险人)
InsuredID = 2
- 史蒂夫乔布斯(被保险人)
InsuredID = 3
- 史蒂夫·巴尔默(伴奏)
InsuredID = 3