开发者

SQL Query crafting

Edited outputs: no file names or trailing slashes are included

I have a database with potentially thousands thousands of records (we're talking a 2MB result string if it was just SELECT * FROM xxx in a standard use case.

Now for reasons of security this result cannot be held anywhere for much more processing.

There is a path field where I want to extract all records with each level of folder structure.

So run the query one way I get every record in the root:

C:\

Query again another way I get every record in the first folder level:

C:\a\
C:\b\

etc

Then of course I will GROUP somehow in order to return

C:\a\
C:\b\

and not

C:\a\
C:\a\
C:\b\
C:\b\

hopefully you get the idea? Any answers that at least move me in the right direction I will be grateful for. I really am stumped where开发者_开发问答 to start with this as downloading every record and processing is far from the ideal solution in my context. (Which is what we do now).

SAMPLE DATA

C:\a\b\c\d
C:\a\b\c
C:\
C:\a\b
C:\g
D:\x
D:\x\y

Sample output 1

C:\
D:\

Sample output 2

C:\a
C:\g
D:\x

sample output 3

C:\a\b
D:\x\y

sample output 4

C:\a\b\c

sample output 5

C:\a\b\c\d


You could do if you have only folders: SELECT DISTINCT path FROM table WHERE LENGTH(path) - LENGTH(replace(path,'\','')) = N

If you have only file names then it depends on whether you have an INSTR function (or some regexp substitution function) provided by the RDBMS. In all cases, depends on the string functions that are available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜