Hierarchical roll-up in SQL accounting system
问题 I'm trying to make annual reports (Balance Sheet and Profit & Loss) from general journal entries in an accounting system. The general journal table (simplified) includes: CREATE TABLE `sa_general_journal` ( `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Date` timestamp NOT NULL DEFAULT current_timestamp(), `Item` varchar(1024) NOT NULL DEFAULT '', `Amount` decimal(9,2) NOT NULL DEFAULT 0.00, `Source` int(10) unsigned NOT NULL, `Destination` int(10) unsigned NOT NULL, PRIMARY KEY (`ID`), KEY