MySQL_Aggregate_Functions

    1. Count

select count(*) from t_grade;
select count(*) as total from t_grade;
select count(*) from t_grade group by stuName;
select stuName, count(*) from t_grade group by stuName;

205526_c3Tr_2363350.png

    2. Sum

select stuName, sum(score) from t_grade where stuName='张三';
select stuName, sum(score) as totalScore from t_grade where stuName='张三';
select stuName, sum(score) as totalScore from t_grade group by stuName;

210316_81Vd_2363350.png

    3. Avg

select stuName, avg(score) as averageScore from t_grade where stuName='张三';
select stuName, avg(score) as averageScore from t_grade group by stuName;

211105_N7Wr_2363350.png

    4. Max

select stuName, max(score) as maxScore from t_grade where stuName='张三';
select stuName, max(score) as maxScore from t_grade group by stuName;
select stuName, course, max(score) as maxScore from t_grade where stuName='张三';
select stuName, course, max(score) as maxScore from t_grade group by stuName; /* False, because 'group by stuName', */
/* so it has to set only 'stuName' after 'select' */

211620_uE6W_2363350.png

212054_XJRN_2363350.png

    5. Min

select stuName, course, min(score) as maxScore from t_grade where stuName='张三';
select stuName, min(score) as maxScore from t_grade group by stuName;

212550_blc6_2363350.png

转载于:https://my.oschina.net/u/2363350/blog/669880

### 字符集支持  - **重要变更:IFNULL()**   (https://dev.mysql.com/doc/refman/9.4/en/flow-control-functions.html#function_ifnull)在 LIKE   (https://dev.mysql.com/doc/refman/9.4/en/string-comparison-functions.html#operator_like)子句中使用时,会触发 ER_CANT_AGGREGATE_2COLLATIONS 错误   (https://dev.mysql.com/doc/mysql-errors/9.4/en/server-error-reference.html#error_er_cant_aggregate_2collations)。   这是因为 IFNULL() 返回二进制排序规则且排序规则派生类型为 NONE,但在此场景下不允许使用 NONE,从而导致错误。    我们通过对语义稍作调整来解决此问题:将排序规则派生类型 NONE 的优先级降低,使其低于其他任何排序规则派生类型的优先级。这意味着,当使用派生类型为 NONE 的表达式时,LIKE 会根据另一个操作数来确定要使用的比较排序规则。这对现有功能的影响应该极小,且我们现有的测试套件无需任何修改。    我们还修改了排序规则聚合逻辑,在确定结果排序规则时,仅考虑具有相同(且最高)优先级的排序规则。此外,我们将之前的 IGNORABLE 派生类型重命名为 NULL,因为它仅用于空值,且由于 NONE 现在的优先级更低,它不再是“可忽略的”。   另外,我们在原 NONE 优先级的值之间留下了一个间隔,以尽量减少 COERCIBILITY()   (https://dev.mysql.com/doc/refman/9.4/en/information-functions.html#function_coercibility)调用返回与先前实现不兼容的值的情况。    有关更多信息,请参见《表达式中的排序规则可 coercibility》   (https://dev.mysql.com/doc/refman/9.4/en/charset-collation-coercibility.html)。(漏洞 #37285902)  
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值