join ,group by

这个是在stackoverflow中找到的一个比较直观的关于join 的视图



group by 语句标准的sql是用到的时候,select 语句中没有用到的聚合函数的字段一定要在group by 后面声明


但是MySQL扩展了标准的sql ,但必须打开ONLY_FULL_GROUP_BY模式,能够不用在group by 后面声明,也可以在select选择该字段,但是这个字段的值一定要相同


MySQL extends the standard SQL use of GROUP BY so that the select list can refer to nonaggregated columns not named in the GROUP BYclause. This means that the preceding query is legal in MySQL. You can use this feature to get better performance by avoiding unnecessary column sorting and grouping. However, this is useful primarily when all values in each nonaggregated column not named in the GROUP BY are the same for each group. The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate. Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Result set sorting occurs after values have been chosen, and ORDER BY does not affect which values within each group the server chooses.


sql 中执行的顺序要是先执行where语句筛选行结果,然后进行group by分组,可以利用分组使用聚合函数来找到自己想要的结果,having 语句是使用在group by以后,再一次的筛选分组的结果,和where的功能差不多,不同的是having可以使用聚合函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值