请教高手union all与group by一起用时出错的一个问题

wjy217213 wjy217213 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
select distinct t1.lineid,'' as linesum,t2.speedlevel,sum(decode(t2.exceptionitem,0,t2.level4count,0)) as a from pw_run_record t1,pw_detect_exceptionstatic t2,pw_detect_tqistatic t3 where t1.detectid=t2.detectid and t1.detectid=t3.detectid
group by t1.lineid,t2.speedlevel
order by t1.lineid,t2.speedlevel
执行上面的语句没问题,但是我想加一个合计
select distinct t1.lineid,'' as linesum,t2.speedlevel,sum(decode(t2.exceptionitem,0,t2.level4count,0)) as a from pw_run_record t1,pw_detect_exceptionstatic t2,pw_detect_tqistatic t3 where t1.detectid=t2.detectid and t1.detectid=t3.detectid
union all
select distinct t1.lineid,'合计' as linesum,t2.speedlevel,sum(decode(t2.exceptionitem,0,t2.level4count,0)) as a from pw_run_record t1,pw_detect_exceptionstatic t2,pw_detect_tqistatic t3 where t1.detectid=t2.detectid and t1.detectid=t3.detectid

group by t1.lineid,t2.speedlevel
order by t1.lineid,t2.speedlevel
因些加上了上面红色的代码,但是报错误提示:
ORA-00904:t2.speedlevel标识符无效
请大家帮忙看一下是什么原因,谢谢大家了

...全文

相关推荐

MySQL中UNION与UNION ALL的基本使用方法

在数据库中,UNION和UNION ALL关键字都是将两个结果集合并为一个,但这两者从使用和效率上来说都有所不同。 MySQL中的UNION UNION在进行表链接后会筛选掉重复的记录,所以在表链接后会对所产生的结果集进行排序运算,删除重复的记录再返回结果。实际大部分应用中是不会产生重复的记录,最常见的是过程表与历史表UNION。如: select * from gc_dfys union select * from ls_jg_dfys 这个SQL在运行时先取出两个表的结果,再用排序空间进行排序删除重复的记录,最后返回结果集,如果表数据量大的话可能会导致用磁盘进行排序。 MySQL中的UN

weixin_38666697

SQL语句 UNION 和 UNION ALL 使用

SQL语句 UNION 和 UNION ALL 使用

superfirefighter

group by的多种用法

详细介绍了cube、rollup、grouping sets的原理及用法

火星人.zhao

浅析mysql union和union all

union 是对数据进行并集操作,不包括重复行,同时进行默认排序而Union all 是对数据进行并集操作,包括重复行,不进行排序,下面给大家详细介绍mysql union和union all,感兴趣的朋友一起看看吧

weixin_38735899

mysql group by 对多个字段进行分组操作

在平时的开发任务中我们经常会用到MYSQL的GROUP BY分组, 用来获取数据表中以分组字段为依据的统计数据。 比如有一个学生选课表,表结构如下: Table: Subject_Selection Subject Semester Attendee ——————————— ITB001 1 John ITB001 1 Bob ITB001 1 Mickey ITB001 2 Jenny ITB001 2 James MKB114 1 John MKB114 1 Erica 我们想统计每门课程有多少个学生报名,应用如

weixin_38729685
评论 10
收藏 已收藏
分享
返回顶部
wjy217213
Oracle 17,134 成员 55,258 内容