如何理解mysql中父查询和子查询之间的关系?

时间:2018-01-24 07:01:31

标签: mysql

有人请解释父查询和子查询之间的区别吗?我怎么理解?

e.g:

  SELECT
        ra.ID id,
        ra.ACCOUNT_ID accountId,
        ef.REAL_NAME realName,
        a.MOBILE mobile,
        sps.`NAME` siteName,
        ef.CREATE_TIME createTime,
        a.`STATUS` status,
        ra.`STATUS` siteStatus,
        (
            SELECT
                aif.APPROVER_NAME
            FROM
                audit_info aif
            WHERE
                aif.TARGET_ID = a.ID AND af.AUDIT_TYPE=2
            AND aif.CREATE_TIME = (
                SELECT
                    MAX(af.CREATE_TIME)
                FROM
                    audit_info af
                WHERE
                    af.TARGET_ID = a.ID AND af.AUDIT_TYPE=2
            )
        ) AS approverName
    FROM
        account a
    INNER JOIN site_relation_account ra ON ra.ACCOUNT_ID = a.ID
    INNER JOIN account_ext ef ON ra.ACCOUNT_ID = ef.ACCOUNT_ID
    INNER JOIN service_provider_site sps ON sps.ID = ra.SITE_ID
    LEFT JOIN audit_info af ON af.TARGET_ID = ef.ACCOUNT_ID
    WHERE ra.ACCOUNT_TYPE = 2

0 个答案:

没有答案