加油努力zmh 2021-12-08 15:42 采纳率: 77.8%
浏览 25
已结题

sql语句执行问题,group by为什么能用select里用过函数生成的字段

date全是这样的日期2025-01-01

select job,date_format(date,'%Y-%m') as mon,sum(num) as cnt
from resume_info
where date>'2025-01-01' and date<'2025-12-31'
group by job,mon
order by mon desc,cnt desc

这个语句竟然能执行,不是group在select之前执行吗,那为什么select生成的mon字段在group by的时候就能被调用了呢,这个时候不是还没有mon字段吗?

  • 写回答

1条回答 默认 最新

  • DarkAthena ORACLE应用及数据库设计方案咨询师 2021-12-09 23:18
    关注

    你这里使用的是别名,这个sql会自动重写为下面这个样子再执行

    select job,date_format(date,'%Y-%m') as mon,sum(num) as cnt
    from resume_info
    where date>'2025-01-01' and date<'2025-12-31'
    group by job,date_format(date,'%Y-%m')
    order by date_format(date,'%Y-%m') desc,cnt desc
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月22日
  • 已采纳回答 12月14日
  • 修改了问题 12月8日
  • 创建了问题 12月8日

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题