我有一个“帐户”表,其中包含带有子帐户(组代码)的组帐户(isgroup):
| code | title | groupcode | isgroup | groupindex | |------|----------------|-----------|---------|------------| | 100 | Current Assets | | 1 | 0 | | 101 | Cash | 100 | 1 | 1 | | 102 | AR | 100 | 1 | 1 | | 103 | Property | | 1 | 0 | | 104 | Balance | | 1 | 0 | | 105 | Cash on hand | 101 | 1 | 2 | | 106 | Cash in bank | 101 | 1 | 2 | | 107 | My Bank 1 | 106 | 0 | 3 | | 108 | Cahier 1 | 105 | 0 | 3 | | 109 | Building 1 | 103 | 0 | 1 |
注意:
我需要这样排序:
| code | title | groupcode | isgroup | groupindex | |------ |---------------- |----------- |--------- |------------ | | 100 | Current Assets | | 1 | 0 | | 101 | Cash | 100 | 1 | 1 | | 105 | Cash on hand | 101 | 1 | 2 | | 108 | Cashier 1 | 105 | 0 | 3 | | 106 | Cash in bank | 101 | 1 | 2 | | 107 | My Bank 1 | 106 | 0 | 3 | | 102 | AR | 100 | 1 | 1 | | 103 | Property | | 1 | 0 | | 109 | Building 1 | 103 | 0 | 1 | | 104 | Balance | | 1 | 0 |
必须首先显示最高级帐户及其不超过n级的子帐户,然后显示下一个最高级帐户。
我已经使用递归函数在应用程序级别完成了任务,并将行一一添加到数据表中。有什么办法可以在一个查询中对该表进行排序?