oracle group by 2列 怎么分组的
3个回答
展开全部
先按照第一列进行分组,再按照第二列进行分组,举例如下:
SELECT ID, NAME, SUM(NUM)
FROM (SELECT 1 AS ID, 'A' AS NAME, 12 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'E' AS NAME, 13 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'A' AS NAME, 14 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'A' AS NAME, 11 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'A' AS NAME, 16 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'D' AS NAME, 19 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'E' AS NAME, 15 AS NUM FROM DUAL) A
GROUP BY ID, NAME
ORDER BY ID, NAME
SELECT ID, NAME, SUM(NUM)
FROM (SELECT 1 AS ID, 'A' AS NAME, 12 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'E' AS NAME, 13 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'A' AS NAME, 14 AS NUM
FROM DUAL
UNION ALL
SELECT 2 AS ID, 'A' AS NAME, 11 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'A' AS NAME, 16 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'D' AS NAME, 19 AS NUM
FROM DUAL
UNION ALL
SELECT 3 AS ID, 'E' AS NAME, 15 AS NUM FROM DUAL) A
GROUP BY ID, NAME
ORDER BY ID, NAME
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-02-06
展开全部
两列一样的进行分组
例如:t表
id name age
1 张三 10
2 李四 20
3 王五 30
4 张三 10
select name ,age from t group by name,age;
上面的查询按照name,age 两列进行分组,分组查询结果
name age
张三 10
李四 20
王五 30
例如:t表
id name age
1 张三 10
2 李四 20
3 王五 30
4 张三 10
select name ,age from t group by name,age;
上面的查询按照name,age 两列进行分组,分组查询结果
name age
张三 10
李四 20
王五 30
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询