我有一個表有多個路徑的共享我想要獲取所有路徑,其中這些路徑中的前N個不同Servername作爲示例在這裏整個表。獲取n個組的所有記錄
+----+--------------------------------+
| ID | BACKUPPATH |
+----+--------------------------------+
| 1 | //server.domain/share/folder |
| 2 | //server.domain/share/folder3 |
| 3 | //server.domain/share/folder2 |
| 4 | //server2.domain/share/folder1 |
| 5 | //server2.domain/share/folder2 |
| 6 | //server3.domain/share/folder1 |
| 7 | //server3.domain/share/folder2 |
| 8 | //server3.domain/share/folder3 |
+----+--------------------------------+
服務器名稱可能會有所不同,每個不同的Servenames可能會有所不同。作爲例子,我希望得到我期望的那樣結果前2個不同servernames節點的所有路徑:
+----+--------------------------------+
| ID | BACKUPPATH |
+----+--------------------------------+
| 1 | //server.domain/share/folder |
| 2 | //server.domain/share/folder3 |
| 3 | //server.domain/share/folder2 |
| 4 | //server2.domain/share/folder1 |
| 5 | //server2.domain/share/folder2 |
+----+--------------------------------+
爲子查詢我用下面的查詢來獲取servernames節點的行集:
select SUBSTRING_INDEX(BACKUPPATH,'/',3) as SERVERNAMES from(select BACKUPPATH from Backuppaths GROUP BY SUBSTRING_INDEX(BACKUPPATH,'/',3))as NUMEROFSERVERS LIMIT 2;
+------------------+
| SERVERNAMES |
+------------------+
| //server.domain |
| //server2.domain |
+------------------+
我被困現在在如何使用這個子查詢來獲得我期望的結果。
感謝在這個
你應該使用'組by'在子查詢中,而不是獨特的:'按服務器名組順序排列m在(id)限制2'中。 OP要求提供前兩個服務器名稱。 – 2014-10-11 14:35:10
@GordonLinoff謝謝,改變 – 2014-10-11 14:49:23
親愛的布萊恩,優秀的作品完美! – TReisser 2014-10-12 07:10:47