简单的sql语句 数据与汇总。 高手多多指点。

源代码在线查看: 数据的分组汇总.sql

软件大小: 11 K
上传用户: janeljh1
关键词: sql 数据 高手
下载地址: 免注册下载 普通下载 VIP

相关代码

				use northwind
				go
				
				select productid,sum(quantity) as [total_quantity] from [order details]
				group by productid
				order by productid
				go
				
				select * from [order details]
				go
				
				select productid,sum(quantity) as [total_quantity] from [order details]
				where productid=2
				group by productid
				go
				
				
				
				select productid,quantity from [order details]
				where productid=2
				go
				
				select productid,sum(quantity) from [order details]
				group by productid
				having productid>=60
				go
				
				--group相当于where,select和where的关系相当于group by和having的关系
				
				select productid,sum(quantity) from (select productid,quantity from  [order details]
				                                     where quantity>=60) as T                       
				                                                
				group by productid
				go
				
				select productid,orderid,sum(quantity) as [total_quantity] from [order details]
				group by productid,orderid
				with rollup
				go 
				
				select productid,orderid,quantity from [order details]
				order by productid,orderid  --必须有这行,不然compute by 不起作用
				compute sum(quantity) by productid
				compute sum(quantity)
				go
				
				select productid,sum(quantity) as [total_quantity] from [order details]
				group by productid
				order by productid
				go
				
							

相关资源