mysql 实例

SELECT
    a.*, FROM_UNIXTIME(
        a.createTime,
        '%Y-%m-%d %H:%i:%s'
    ) AS createTimeStr,
    FROM_UNIXTIME(
        a.updateTime,
        '%Y-%m-%d %H:%i:%s'
    ) AS updateTimeStr,
    b.`orgName` AS deptName,
    c.`realUserName` AS userName,
    d.`realUserName` AS updateName
FROM
    (
        SELECT
            v.*, (
                SELECT
                    COUNT(*)
                FROM
                    wx_article_info w
                WHERE
                    w.wxCode = v.wxCode
            ) AS articleCount
        FROM
            wx_base_info v
        LEFT JOIN sys_users su ON v.`userId` = su.`userId`
        WHERE
            1 = 1
        AND v.cityCode LIKE CONCAT('34', '%')
        AND v.deptCode LIKE concat('34', '%')
    ) a
LEFT JOIN sys_org b ON a.`deptCode` = b.`orgCode`
LEFT JOIN sys_users c ON a.`userId` = c.`userId`
LEFT JOIN sys_users d ON a.`updateId` = d.`userId`
WHERE
    1 = 1
ORDER BY
    a.updateTime DESC,
    a.articleCount DESC

 

上一篇:Spring系列之集成MongoDB的2种方法


下一篇:分享两道阿里前端笔试题