首页 > 代码库 > sql复杂的子查询,横向合并结果集
sql复杂的子查询,横向合并结果集
第一个查询的结果集
select * from(select c.msName,a.msId,c.msPrice, c.msPrice*COUNT(a.msId) as totalMoney,sum(a.msAmount) as totalCount from BillConsume a right join (select top 1 msTime as startTime,GETDATE() as endTime from BillConsume where DateDiff(dd,msTime,getdate())=0 order by msTime asc) b on a.msTime between b.startTime and b.endTime and a.msId!=0left join Menus c on c.msId=a.msId group by a.msId ,c.msName,c.msPrice)s
连接两个结果集的语句
full join
第二个查询的结果集
(select sum(t.totalMoney) as allTotalMoney from ( select c.msName,a.msId,c.msPrice, c.msPrice*COUNT(a.msId) as totalMoney,sum(a.msAmount) as totalCount from BillConsume a right join (select top 1 msTime as startTime,GETDATE() as endTime from BillConsume where DateDiff(dd,msTime,getdate())=0 order by msTime asc) b on a.msTime between b.startTime and b.endTime and a.msId!=0left join Menus c on c.msId=a.msId group by a.msId ,c.msName,c.msPrice)t)t
连表的条件
on 1=1
sql复杂的子查询,横向合并结果集
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。