1. SQL / Говнокод #24

    −401.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    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

    Запостил: guest, 27 Ноября 2008

    Комментарии (17) RSS

    Добавить комментарий