现在有这么个需求:订单完成后,商家可以获得收益,同时商家也可以提现。但是收益表和提现表是两张表,如何合并显示这两张表的记录呢?
收益表如下:
提现表如下:
这两张表字段不同,但是使用union的时候必须两张表的字段相同才能union,并用tradeType将收入和提现区分,union后再按时间顺序排序;
看一下union后的效果:
下面展示一些 内联代码片
。
// An highlighted block
var data = await _commissionServices.QuerySqlPage(@" select id,order_id,commissionMoney,commissionBalance,createTime,tradeType from
(select id,order_id,commissionMoney,commissionBalance,createTime ,tradeType=1 from [Commission] where user_id=@user_id and isDeleted=0
union
select id,order_id=null,money as commissionMoney,commissionBalance =0,creationTime as createTime,tradeType=2 from [Cash_draws] where user_id=@user_id and targetType=4 and status=1 and isDeleted=0
)as t order by createTime desc", dto.pageIndex, dto.pageSize,
new SqlSugar.SugarParameter[] { new SqlSugar.SugarParameter("@user_id", user_id) });