Sql Server Rollup 語句的用法
CREATE TABLE tblPopulation (
Country VARCHAR(100),
[State] VARCHAR(100),
City VARCHAR(100),
[Population (in Millions)] INT
)
GO
INSERT INTO tblPopulation VALUES('India', 'Delhi','East Delhi',9 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','South Delhi',8 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','North Delhi',5.5)
INSERT INTO tblPopulation VALUES('India', 'Delhi','West Delhi',7.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Bangalore',9.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Belur',2.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Manipal',1.5)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Mumbai',30)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Pune',20)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Nagpur',11 )
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Nashik',6.5)
GO
SELECT Country,[State],City,
SUM ([Population (in Millions)]) AS [Population (in Millions)]
FROM tblPopulation
GROUP BY Country,[State],City WITH ROLLUP
Country VARCHAR(100),
[State] VARCHAR(100),
City VARCHAR(100),
[Population (in Millions)] INT
)
GO
INSERT INTO tblPopulation VALUES('India', 'Delhi','East Delhi',9 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','South Delhi',8 )
INSERT INTO tblPopulation VALUES('India', 'Delhi','North Delhi',5.5)
INSERT INTO tblPopulation VALUES('India', 'Delhi','West Delhi',7.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Bangalore',9.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Belur',2.5)
INSERT INTO tblPopulation VALUES('India', 'Karnataka','Manipal',1.5)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Mumbai',30)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Pune',20)
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Nagpur',11 )
INSERT INTO tblPopulation VALUES('India', 'Maharastra','Nashik',6.5)
GO
SELECT Country,[State],City,
SUM ([Population (in Millions)]) AS [Population (in Millions)]
FROM tblPopulation
GROUP BY Country,[State],City WITH ROLLUP
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16436858/viewspace-628594/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL語句IN的用法SQL
- SQL 語句 as 的用法SQL
- sql宣告變數,及if -else語句、while語句的用法SQL變數While
- Sql Server系列:Update語句SQLServer
- Sql Server系列:Delete語句SQLServerdelete
- SQL server 查詢語句SQLServer
- sql server中常用語句SQLServer
- DBA常用SQL語句[sql server] 2SQLServer
- MySql與Sql Server Update語句MySqlServer
- SQL Server阻塞查詢語句SQLServer
- Sql Server系列:Insert語句SQLServer
- SQL SERVER 流程控制語句SQLServer
- SQL Server SQL語句執行順序SQLServer
- SQL Server FOR XML PATH 語句的應用SQLServerXML
- SQL SERVER 條件語句的查詢SQLServer
- Sql server 的update語句的新認識SQLServer
- SQL Server優化之SQL語句優化SQLServer優化
- Sql Server系列:資料控制語句SQLServer
- Sql Server系列:流程控制語句SQLServer
- Sql Server系列:Select基本語句SQLServer
- SQL Server 查詢歷史執行的SQL語句SQLServer
- SQL Server語句的自動優化工具SQLServer優化
- 匯出Sql Server資料字典的語句SQLServer
- sql server 中的一些實用的sql語句SQLServer
- sql中as的用法和一些經典的sql語句SQL
- sql server with ...as 用法SQLServer
- SQL Server SQL語句進行優化的基本原則SQLServer優化
- SQL Server-簡單查詢語句SQLServer
- Sql Server系列:查詢分頁語句SQLServer
- SQL Server 語句日期格式查詢方法SQLServer
- 【SQL Server學習筆記】Delete 語句、Output 子句、Merge語句SQLServer筆記delete
- python關於pymysql 執行sql語句in的用法PythonMySql
- SQL Server SQL語句進行優化的基本原則 (轉)SQLServer優化
- SQL SERVER 中構建執行動態SQL語句SQLServer
- JavaScript with 語句用法JavaScript
- Oracle Hints語句的用法Oracle
- Python with 語句的用法Python
- SQL Server之資料庫語句優化SQLServer資料庫優化