How to query folder and document both so that we can get:
I took the liberty to name queries a bit differently than OP asked it, but it fits it too. It is just a bit more clearer what some query returns. I used Temp folder for this example.
SELECT * FROM dm_document WHERE FOLDER('/Temp', DESCEND)
SELECT * FROM dm_document WHERE FOLDER('/Temp')
SELECT COUNT(doc.r_object_id) AS doc_ammount, fol.object_name AS folder_object_name FROM dm_document doc, dm_folder fol WHERE FOLDER('/Temp', descend) AND ANY doc.i_folder_id = fol.r_object_id GROUP BY (fol.object_name)