1:Union语句: 把两个结果合为一体(但是完全重复的数据会去掉)
Eg1: select name, age, ‘学生无工资’ from student
union
select name, age, sal from teacher
Eg2: select top 2 CONVERT(varchar(20),itemId) itemid, fee, addDate from Orders
union
select ‘合计‘,SUM(fee),GETDATE() from (select top 2 fee from Orders) a
2:Union All (重复的数据不会去掉)
工资合计效果:Select name, sal from teacher
union all
select ‘工资合计’, sum(sal) from teacher
时间: 2024-11-09 00:29:35