码迷,mamicode.com
首页 > 数据库 > 详细

对账sql

时间:2015-12-20 11:45:00      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

技术分享

 

SELECT
    *
FROM
    (
        SELECT
            t.id t_id,
            t.order_no t_order_no,
            t.amount t_amount,
            t.type t_type,
            w.id w_id,
            w.order_no w_order_no,
            w.amount w_amount
        FROM
            (
                SELECT
                    tr.id,
                    tr.order_no,
                    tr.amount,
                    tr.type
                FROM
                    trade tr
                WHERE
                    tr.type = 1
            ) t
        LEFT JOIN wx w ON t.order_no = w.order_no
        AND t.amount = w.amount
        UNION
            SELECT
                t.id t_id,
                t.order_no t_order_no,
                t.amount t_amount,
                t.type t_type,
                w.id w_id,
                w.order_no w_order_no,
                w.amount w_amount
            FROM
                (
                    SELECT
                        tr.id,
                        tr.order_no,
                        tr.amount,
                        tr.type
                    FROM
                        trade tr
                    WHERE
                        tr.type = 1
                ) t
            RIGHT JOIN wx w ON t.order_no = w.order_no
            AND t.amount = w.amount
    ) u
WHERE
    u.t_id IS NULL
OR u.w_id IS NULL

 

技术分享

 

对账sql

标签:

原文地址:http://www.cnblogs.com/liuyifan/p/5060461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!