Enumerating the mySQL Querying path to create breadcrumbs

I would like to create breadcrumbs from an enumerated column of the path.

Here is an example of a dataset that I have.

https://spreadsheets.google.com/ccc?key=0AsGYQbeSAIgFdGRscFpsZFJpQUtfWGIwYWNUY2ktRHc&hl=en_GB&authkey=CPOuuogF

id woeid parent_woeid country_code name language place_type ancestry

Ancestors are an enumerated path, such as 1/23424975/24554868/12602167/12696151- this is the path for Brighton in England.

I would like to be able to find the breading by querying the columns nameand get all the parents.

t. World, Europe, England, [County], [City], [Region], [Place]

([] = a placeholder)

The data never changes, so this table uses the Adjacency List and path enumeration.

+3
source share
1 answer

. , , , .

, (, ) SQL (. "An employee FORD and chain of his supervisors"). - , - IN:

SELECT *
FROM woe
WHERE ancestry IN (
    '1', 
    '1/23424975', 
    '1/23424975/24554868', 
    '1/23424975/24554868/12602167', 
    '1/23424975/24554868/12602167/12696151'
)
ORDER BY LEN(ancestry)

Adjacency List Common Table Expression CONNECT BY ( ancestry). . Adjacency List (. ).

, , . - , , SQL, , . - , . MySQL, , , , .

- , , , , , .

+5

Source: https://habr.com/ru/post/1785563/


All Articles