The code would work on most engines that support CTEs, with some changes to the type casting syntax.
Thus most except MySQL.