5 kyu
SQL Basics: Simple Hierarchical structure
2,884matt c
Loading description...
SQL
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
This comment has been hidden.
Very nice exercise to understand recursion properly!
This is legit the best thing I have done with SQL. I didn't even know SQL had a recursive query.
Great kata for understanding recursive query!
In general the rules of defining levels: let employee of id = n have level m. Then we look for the employee whose manager's id is n and assign him level (m + 1). I don't think that's any kind of spoiler. Hope it clarifies the kata which is really cool.
very interesting kata, thank you
This one was lovely. I sometimes work with hierarchical data and have been struggling with 'levels' in postgres. This kata allowed me to pinpoint exactly what I was missing!
Great kata, surpisingly 'brain teasing'. This article really helped me conceptualise the problem in a better way: http://lextoumbourou.github.io/blog/posts/understanding-recursive-queries-in-postgresql/
Found it helpful, too, but original link is dead. Here's the achive link: https://web.archive.org/web/20200601114227/http://lextoumbourou.github.io/blog/posts/understanding-recursive-queries-in-postgresql/
This kata should more clearly specify how "level" should be defined.
Hope that helps.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Very nice kata, tried it first months ago but could not understand what the level was supposed to be, came back to it today and managed to figure it out eventually.
Learned a lot, thanks :)
Thanks :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
These articles helped me to resolve this kata:
https://www.citusdata.com/blog/2018/05/15/fun-with-sql-recursive-ctes/
http://blog.timothyandrew.net/blog/2013/06/24/recursive-postgres-queries/
Good articles, thank you, one of them pointed me in the right direction. This one helped me along them as well: https://www.essentialsql.com/recursive-ctes-explained/ After dealing mostly with ORMs and programmatic solutions of complex DB queries, this kata seemed confusing, but once solved, it's quite fascinating.
My solution appears to be generating the correct answers when I compare the actual vs expected tables, but the very last test gives this error:
should should return the expected results ✘ expected true to respond to
true?
or perhaps you meantbe true
orbe_truthy
?
this is a codewards error.
Great Kata. I wanted to make something similar (as a basic version of my Hierarchy Kata), but now you have been faster :) Looks like most of SQL's basic concepts have already been covered.
By the way, you have an typo in your description: You are describing the "employeees" table, but it's actual name is "employees". Count the 'e's ;)
thanks, fixed