日期:2014-05-18 浏览次数:20502 次
--> 测试数据:[tb] IF OBJECT_ID('[tb]') IS NOT NULL DROP TABLE [tb] GO CREATE TABLE [tb]([col1] INT,[col2] INT,[col3] INT) INSERT [tb] SELECT 1,3,5 UNION ALL SELECT 1,3,5 UNION ALL SELECT 2,1,8 UNION ALL SELECT 2,1,8 UNION ALL SELECT 3,2,3 UNION ALL SELECT 3,2,3 UNION ALL SELECT 4,0,NULL UNION ALL SELECT 4,0,NULL --------------开始查询-------------------------- SELECT * FROM [tb] GROUP BY [col1] ,[col2] ,[col3] SELECT * FROM [tb] GROUP BY [col3] ,[col2] ,[col1] SELECT * FROM [tb] GROUP BY [col2] ,[col3] ,[col1] SELECT * FROM [tb] GROUP BY [col1] ,[col2] ,[col3] ORDER BY [col1] ,[col2] ,[col3] SELECT * FROM [tb] GROUP BY [col3] ,[col2] ,[col1] ORDER BY [col1] ,[col2] ,[col3] SELECT * FROM [tb] GROUP BY [col2] ,[col3] ,[col1] ORDER BY [col1] ,[col2] ,[col3] /* col1 col2 col3 ----------- ----------- ----------- 1 3 5 2 1 8 3 2 3 4 0 NULL (4 行受影响) col1 col2 col3 ----------- ----------- ----------- 4 0 NULL 3 2 3 1 3 5 2 1 8 (4 行受影响) col1 col2 col3 ----------- ----------- ----------- 4 0 NULL 2 1 8 3 2 3 1 3 5 (4 行受影响) col1 col2 col3 ----------- ----------- ----------- 1 3 5 2 1 8 3 2 3 4 0 NULL (4 行受影响) col1 col2 col3 ----------- ----------- ----------- 1 3 5 2 1 8 3 2 3 4 0 NULL (4 行受影响) col1 col2 col3 ----------- ----------- ----------- 1 3 5 2 1 8 3 2 3 4 0 NULL (4 行受影响) */