SQL注入: with rollup特性

題目名稱:因缺思汀的繞過
題目地址: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

相關文章
相關標籤/搜索