将sql语句合并为一条sql语句

星宵山 2017-08-14 11:29:57
我对两张表进行不同的查询,数据如下
表一:


sql 1:
select xn,xqm,xh 学号,round(avg(jd),2) 平均绩点 from T_XS_CJZLB where SCBZ= 'n' and XH in (select xh from t_xs_xsjbxxb where bjmc='14机械制造与自动化2') and xn='2014-2015' and xqm='2' group by xh,xn,xqm order by xn,xqm,平均绩点

表二:


sql 2:
select
kh 学号,
round((count(lsh)/348),2)*100||'%' 就餐率
from T_YKT_XFJL
where nd='2015' and KH in (select xh from t_xs_xsjbxxb where bjmc='14机械制造与自动化2') and shlxmc='就餐' and yf in (3,4,5,6,7) group by kh order by 就餐率



求大神指教,怎么把两条sql语句合并,让两张表中的数据合为一张表
谢谢!!!!!!!
...全文
406 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
卖水果的net 2017-08-14
  • 打赏
  • 举报
回复
with t as( select 学号,绩点,'' 餐率 from t1 -- 第一个查询 union all select 学号,'' 绩点,餐率 from t2 -- 第二个查询 ) select 学号,max(绩点),max(餐率) from t group 学号
mayanzs 2017-08-14
  • 打赏
  • 举报
回复
你的括号用了全角字符了吧?
星宵山 2017-08-14
  • 打赏
  • 举报
回复
with t as( select xn,xqm,xh 学号,round(avg(jd),2) 平均绩点 from T_XS_CJZLB where SCBZ= 'n' and XH in (select xh from t_xs_xsjbxxb where bjmc='14机械制造与自动化2') and xn='2014-2015' and xqm='2' group by xh,xn,xqm order by xn,xqm,平均绩点 union all select kh 学号, round((count(lsh)/348),2)*100||'%' 就餐率 from T_YKT_XFJL where nd='2015' and KH in (select xh from t_xs_xsjbxxb where bjmc='14机械制造与自动化2') and shlxmc='就餐' and yf in (3,4,5,6,7) group by kh order by 就餐率 ) select 学号,平均绩点,就餐率 from t group 学号 是不是这样,但这样报错啊,显示‘缺失右括号’ 麻烦,大神了

3,497

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧