两张字段不同的表,查询时将记录合在一起

表一:

两张字段不同的表,查询时将记录合在一起_第1张图片

表二:

两张字段不同的表,查询时将记录合在一起_第2张图片

语句:

SELECT
    `gid`,
    `station_id`,
    `zone_id`,
    `ecode`,
    `user_id`,
    `user_name`,
    `check_user_id`,
    `check_user_name`,
    `check_time`,
    `sign_date`,
    `sign_time`,
    `longitude`,
    `latitude`,
    `check_status`,
    `address`,
    `record_name`,
    NULL AS restApplyTime,
    NULL AS restCheckerId,
    NULL AS restStartTime,
    NULL AS restReason,
    NULL AS restCheckComment,
    NULL AS restEndTime,
    NULL AS restStatus
FROM
    duty_sign_record
UNION ALL
    SELECT
        `gid`,
        `station_id`,
        `zone_id`,
        `ecode`,
        `user_id`,
        `user_name`,
        `checker_id` AS restCheckerId,
        `checker_name` AS restCheckerName,
        `check_time`,
        NULL AS sign_date,
        NULL AS sign_time,
        NULL AS longitude,
        NULL AS latitude,
        NULL AS check_status,
        NULL AS check_user_id,
        NULL AS address,
        NULL AS record_name,
        `apply_time` AS restApplyTime,
        `start_time` AS restStartTime,
        `reason` AS restReason,
        `check_comment` AS restCheckComment,
        `end_time` AS restEndTime,
        `status` AS restStatus
    FROM
        `duty_rest`
    ORDER BY
        gid ASC;

你可能感兴趣的:(数据库)