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

版权声明:转载请注明出处http://blog.csdn.net/chanryma https://blog.csdn.net/chanryma/article/details/79573818

表一:

表一

表二:

表二

语句:

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;
展开阅读全文

没有更多推荐了,返回首页