Example 1
1 | SELECT |
1 | SELECT |
1 | SELECT |
Example 2
table1
2
3
4
5
6
7
8
9
10
11
12+------+------+------+-------+
| pkey | name | exam | score |
+------+------+------+-------+
| 1 | Bob | 1 | 75 |
| 2 | Bob | 2 | 77 |
| 3 | Bob | 3 | 78 |
| 4 | Bob | 4 | 80 |
| 5 | Sue | 1 | 90 |
| 6 | Sue | 2 | 97 |
| 7 | Sue | 3 | 98 |
| 8 | Sue | 4 | 99 |
+------+------+------+-------+
way-1
1 | select name, |
way-2
1 | SELECT name, |
result1
2
3
4
5
6+------+-------+-------+-------+-------+
| name | exam1 | exam2 | exam3 | exam4 |
+------+-------+-------+-------+-------+
| Bob | 75 | 77 | 78 | 80 |
| Sue | 90 | 97 | 98 | 99 |
+------+-------+-------+-------+-------+
Example 3
My Problem
Daily Customer Growth and Daily Customer Growth by Gender
1 | select date_format(SignedUp,'%Y%m%d') days, |
unsolved problem
- unpivot in mysql:
- Pivot table with dynamic columns in MySQL:http://stratosprovatopoulos.com/web-development/mysql/pivot-table-with-dynamic-columns/
- pivot function in SQL server: http://www.codeproject.com/Tips/500811/Simple-Way-To-Use-Pivot-In-SQL-Query
https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx.aspx)reference
datacharmer.org/downloads/pivot_tables_mysql_5.pdf
http://blog.csdn.net/redwood_lin/article/details/1550606
http://www.artfulsoftware.com/infotree/qrytip.php?id=78