统计 sqlServer grouping with Rollup
2017-04-18 17:53
316 查看
select
case grouping( CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice)))
when 0 then CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice))
when 1 then '总计'
end as 'XX',
COUNT(O.orderId ) '单数',SUM(O.ticketCount) '张数'
from [Order] O
inner join [OrderElec] oe on O.orderId =oe.OrderId and oe.PrintType>0
inner join [SessionSeatPriceType] SSP on SSP.SeatTicketTypeSessionId=O.sessionId and O.orderSellPriceType=SSP.seatTicketTypePriceID
where O.sessionid =XX
and O.orderType=XX
and O.orderMode=XX
and O.orderVisable=XX
and O.orderPayment=XX
group by CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice)) with Rollup
case grouping( CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice)))
when 0 then CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice))
when 1 then '总计'
end as 'XX',
COUNT(O.orderId ) '单数',SUM(O.ticketCount) '张数'
from [Order] O
inner join [OrderElec] oe on O.orderId =oe.OrderId and oe.PrintType>0
inner join [SessionSeatPriceType] SSP on SSP.SeatTicketTypeSessionId=O.sessionId and O.orderSellPriceType=SSP.seatTicketTypePriceID
where O.sessionid =XX
and O.orderType=XX
and O.orderMode=XX
and O.orderVisable=XX
and O.orderPayment=XX
group by CONVERT(VARCHAR(20),CONVERT(DECIMAL(20,0),SSP.SeatTicketTypePrice)) with Rollup
相关文章推荐
- SQL Server WITH ROLLUP、WITH CUBE、GROUPING语句的应用
- SQL 关于with cube ,with rollup 和 grouping
- [转载 from SQL Server 2000 Help] SQL Server中汇总功能的使用GROUPING,ROLLUP和CUBE
- sql grouping with rollup 按部门 合并一些部门
- Sql学习第四天——SQL 关于with cube ,with rollup 和 grouping
- SQL 关于apply的两种形式cross apply 和 outer apply, with cube 、with rollup 和 grouping
- Returning Ranked Results with Microsoft SQL Server 2005
- SqlServer with(nolock)
- Working with SQL Server LocalDB
- Encrypting Data With the SQL Server Encrypt Function
- How To: Use Forms Authentication with SQL Server in ASP.NET 2.0
- Using ROW_NUMBER() to paginate your data with SQL Server 2005 and ASP.NET
- SQL Server 64 bit linked server Error with Sql server 32 bit
- grouping、with rollup的用法。
- DBCC大全集之(适用版本MS SQLServer 2008 R2)----DBCC SQLPERF提供所有数据库的事务日志空间使用情况统计信息
- error while performing databases login with sqlserver driver:unable to create connection
- The user is not associated with a trusted SQL Server Connection
- SQLServer WITH 的用法
- "Not associated with a trusted SQL Server connection"解决方法
- OLAP函数系列1:SqlServer中分组函数GROUP BY 的扩展:all, cube,roolup与grouping