字段数量必须一样!!!  切记 

多张不同表,使用union all解决合并查询

$arr['CurrencyStatus'] = " a.RechargeCardStatus = 3 ";
$arr['Status'] = " 1=1 ";

$Keyword = rtrim($_GET['Keyword']);
$search .= " and (
abc.MemberID like '%{$Keyword}%'
or abc.Mobile like '%{$Keyword}%'
or abc.CurrencyCaedType like '%{$Keyword}%'
or abc.RechargeCardPrice like '%{$Keyword}%'
or abc.RechargeCode like '%{$Keyword}%'
or abc.CurrencyCount like '%{$Keyword}%'
)";

$sql = "

select * from (
(
select
a.RechargeCode,
null as WxOrderId,
a.MemberID,
b.Mobile,
a.ChannelId,
c.Name as ChannelName,
a.RechargeCardTime,
a.CurrencyName,
a.RechargeCode as RechargeType,
a.RechargeCardPrice,
a.CurrencyPrice,
a.CurrencyCount,
a.CurrencyStatus
from Tbl_CZK_RechargeCard as a
left join Tbl_Member as b on a.MemberID = b.MemberID
left join Tbl_CZK_Channel as c on c.ChannelId = a.ChannelId
where {$arr['CurrencyStatus']}
)
union all
(
select
g.OrderId as RechargeCode,
g.WxOrderId,
g.MemberID,
h.Mobile,
g.ChannelId,
i.Name as ChannelName,
g.CreateTime as RechargeCardTime,
g.CurrencyName,
g.OrderId as RechargeType,
g.Cash as RechargeCardPrice,
g.CurrencyPrice as CurrencyPrice,
g.CurrencyNum as CurrencyCount,
g.Status CurrencyStatus
from Tbl_CZK_RechargeOrder as g
left join Tbl_Member as h on h.MemberID = g.MemberID
left join Tbl_CZK_Channel as i on i.ChannelId = g.ChannelId
where {$arr['Status']}
)
) as abc
where {$search}

order by abc.RechargeCardTime desc

limit 1,10

";

多张不同表,使用union all解决多张数据表的去重统计


$sql = "
select COUNT(DISTINCT abc.MemberID) as num from (
(
select
a.MemberID
from Tbl_CZK_RechargeCard as a
where a.RechargeCardStatus = 3  and a.RechargeCardTime >= ".$startTime." and a.RechargeCardTime <= ".$endTime."
)
union all
(
select
g.UserId as MemberID
from Tbl_CZK_RechargeOrder as g
where  g.UpdateTime >= ".$startTime." and g.UpdateTime <= ".$endTime."
)
) as abc
";