表格ChannelReward和表格RewardSuppleSettle中都有一下几个字段JSMonth, ChannelNo, RewardSum, RewardItem。要将两个表中RewardSum>0的记录都显示在一个表中,可以使用联合查询
select * from(
SELECT JSMonth, ChannelNo, RewardSum, RewardItem, ‘1‘ AS ObjectType
FROM dbo.ChannelReward
WHERE (RewardSum > 0)
UNION ALL
SELECT JSMonth, ChannelNo, Reward AS RewardSum, ItemName AS RewardItem, ‘1‘ AS ObjectType
FROM RewardSuppleSettle
WHERE (Reward > 0))t where t.ChannelNo=‘1003‘
union联合查询将两个表的查询结果在一个表中显示,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/hongyan5682/p/3832355.html