题目名称:因缺思汀的绕过
题目地址:http://www.shiyanbar.com/ctf/1940mysql
一、with rollup:
with rollup关键字会在全部记录的最后加上一条记录,该记录是上面全部记录的总和。
二、group_concat():
group by与group_concat()函数一块儿使用时,每一个分组中指定字段值都显示出来sql
select sex,group_concat(name) from employee group by sex; mysql> select sex,group_concat(name) from employee group by sex; +------+------+-----------+ | sex |group_concat(name) | +------+------+-----------+ | 女 | 李四 | | 男 | 张三,王五,Aric | +------+------+-----------+ 2 rows in set (0.00 sec)
例一、普通的 GROUP BY 操做,能够按照部门和职位进行分组,计算每一个部门,每一个职位的工资平均值:函数
mysql> select dep,pos,avg(sal) from employee group by dep,pos; +------+------+-----------+ | dep | pos | avg(sal) | +------+------+-----------+ | 01 | 01 | 1500.0000 | | 01 | 02 | 1950.0000 | | 02 | 01 | 1500.0000 | | 02 | 02 | 2450.0000 | | 03 | 01 | 2500.0000 | | 03 | 02 | 2550.0000 | +------+------+-----------+ 6 rows in set (0.02 sec)
例二、若是咱们但愿显示部门的平均值和所有雇员的平均值,普通的 GROUP BY 语句是不能实现的,须要另外执行一个查询操做,或者经过程序来计算。若是使用有 WITH ROLLUP 子句的 GROUP BY 语句,则能够轻松实现这个要求:.net
mysql> select dep,pos,avg(sal) from employee group by dep,pos with rollup; +------+------+-----------+ | dep | pos | avg(sal) | +------+------+-----------+ | 01 | 01 | 1500.0000 | | 01 | 02 | 1950.0000 | | 01 | NULL | 1725.0000 | | 02 | 01 | 1500.0000 | | 02 | 02 | 2450.0000 | | 02 | NULL | 2133.3333 | | 03 | 01 | 2500.0000 | | 03 | 02 | 2550.0000 | | 03 | NULL | 2533.3333 | | NULL | NULL | 2090.0000 | +------+------+-----------+ 10 rows in set (0.00 sec)
文章来源:http://blog.csdn.net/shachao888/article/details/46490089code