oracle数据库中如何达到像mysql数据库中group by 那种去重的效果..求大神解答

2025-03-24 01:20:32
推荐回答(1个)
回答1:

oracle和mysql,group by是由区别的。
oracle的gruop by 后跟的必须是select查询出的字段
而且group by语句中select指定的字段必须是“分组依据字段”,其他字段若想出现在select中则必须包含在聚合函数中
聚合函数比如:
sum(列名) 求和     
max(列名) 最大值     
min(列名) 最小值     
avg(列名) 平均值     
count(列名) 统计记录数 注意和count(*)的区别
select a.app_name as dealInfoId,
SUM(CASE
WHEN l.ser_type = '日常客服' then
1
else
0
end) as rc,
SUM(CASE
WHEN l.ser_type = '温馨提示' then
1
else
0
end) as wx,
SUM(CASE
WHEN l.ser_type = '更新提示' then
1
else
0
end) as gx,
SUM(CASE
WHEN l.ser_type = '回访' then
1
else
0
end) as hf,
SUM(CASE
WHEN l.ser_type = '培训' then
1
else
0
end) as px
FROM work_info_log l, config_app a
where l.config_app = a.id
and l.office_id in (34, 500201)
group by a.app_name;