SQL注入: with rollup特性

题目名称:因缺思汀的绕过
题目地址:http://www.shiyanbar.com/ctf/1940

1、with rollup:
with rollup关键字会在所有记录的最后加上一条记录,该记录是上面所有记录的总和。
2、group_concat():
group by与group_concat()函数一起使用时,每个分组中指定字段值都显示出来

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)  

例1、普通的 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)  

例2、如果我们希望显示部门的平均值和全部雇员的平均值,普通的 GROUP BY 语句是不能实现的,需要另外执行一个查询操作,或者通过程序来计算。如果使用有 WITH ROLLUP 子句的 GROUP BY 语句,则可以轻松实现这个要求:

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/46490089

原文地址:https://www.cnblogs.com/litlife/p/7800011.html