The great thing about it is that it's just one SQL statement.
One SQL statement with recursion ughhh, arghhhh ... a bit older but still quite complicated to me - I've spent many hours on it and still cannot fully understand how it works(this recursion thingy with all the university variables memories - i,k,j , do you remember them :)). Definitely a good brain teaser, good luck.
http://sqlfiddle.com/ (just select Oracle 11g R2 instead of MySQL from the drop down -> press Build Schema -> paste the SQL statment into the right window -> Run SQL )
One SQL statement with recursion ughhh, arghhhh ... a bit older but still quite complicated to me - I've spent many hours on it and still cannot fully understand how it works(this recursion thingy with all the university variables memories - i,k,j , do you remember them :)). Definitely a good brain teaser, good luck.