Mistři v programování na #hovnokod

SQL #371

SELECT *
FROM (SELECT n.root, n.nodeid, n.name, UNIX_TIMESTAMP(m.createtime) AS
 updatetime, (SELECT COUNT(*) FROM fs_node WHERE sid = n.sid AND root = n.root
  AND cleft > n.cleft AND cright < n.cright AND clevel = n.clevel + 1 AND
   nodetype = 1) AS objcount FROM fs_node AS n, fs_node AS m WHERE n.sid = $ sid
    AND n.root IN (0, 1, 2, 3) AND n.nodetype = 0 AND m.nodeid =(SELECT MAX(
    nodeid) FROM fs_node WHERE sid = n.sid AND root = n.root AND cleft > n.cleft
     AND cright < n.cright AND clevel = n.clevel + 1 AND nodetype = 1) UNION ALL
     SELECT n.root, NULL, NULL, UNIX_TIMESTAMP(m.createtime) AS updatetime, (
     SELECT COUNT(*) FROM fs_node WHERE sid = $ sid AND root = n.root AND clevel
      = 1 AND nodetype = 1) AS objcount FROM (SELECT 0 AS root UNIONSELECT 1
       UNIONSELECT 2 UNIONSELECT 3) AS n, fs_node AS m WHERE m.nodeid =(SELECT
        MAX(nodeid) FROM fs_node WHERE sid = $ sid AND root = n.root AND clevel
         = 1 AND nodetype = 1)) AS tmp
ORDER BY updatetime DESC

HovnoKod,