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宣告變數,及if -else語句、while語句的用法SQL變數While
- SQL Server 查詢歷史執行的SQL語句SQLServer
- SQL Server 語句日期格式查詢方法SQLServer
- SQL Server-簡單查詢語句SQLServer
- python關於pymysql 執行sql語句in的用法PythonMySql
- Sql server with as update用法SQLServer
- Python with 語句的用法Python
- Sql Server 資料庫獲取字串中小寫字母的SQL語句SQLServer資料庫字串
- JavaScript with 語句用法JavaScript
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- SQL語句SQL
- SQL Server 資料庫部分常用語句小結(二)SQLServer資料庫
- SQL server資料庫表碎片比例查詢語句SQLServer資料庫
- SQL Server 資料庫部分常用語句小結(一)SQLServer資料庫
- MySQL 中 WITH ROLLUP 用法MySql
- MySQL 的 EXPLAIN 語句及用法MySqlAI
- 【SQL】9 SQL INSERT INTO 語句SQL
- 【SQL】10 SQL UPDATE 語句SQL
- 【SQL】11 SQL DELETE 語句SQLdelete
- SQL SELECT 語句SQL
- sql常用語句SQL
- sql語句如何執行的SQL
- MySQL中常用的SQL語句MySql
- sqlserver dba常用的sql語句SQLServer
- SQL 語句的注意事項SQL
- 1.3. SQL 語句SQL
- Oracle基本SQL語句OracleSQL
- Sql語句小整理SQL
- SQL語句優化SQL優化
- SQL 語句學習SQL
- 資料庫常用的sql語句大全--sql資料庫SQL
- SQL Server郵件相關SQL語句出現嚴重的ASYNC_NETWORK_IO等待事件案例SQLServer事件
- insert all和insert first語句的用法
- Laravel 子查詢語句用法Laravel
- Oracle SQL精妙SQL語句講解OracleSQL
- 單個SQL語句的10046 traceSQL
- mysql的sql語句執行流程MySql
- SQL語句規範的寫法SQL