Also this may be a bit more than you asked for but I just put up a blog
entry a couple days going through CTE's generally and how we use them in
LedgerSMB. You might find it helpful.
http://ledgersmbdev.blogspot.com/2012/07/ctes-and-ledgersmb.html
Best Wishes,
Chris Travers