I start to learn how to write sql language but I got stuck with the problem below : Now I have a data in a table named 'data'
+------+-------+-------+-------+-------+
| id | name | type1 | type2 | type3 |
+------+-------+-------+-------+-------+
| 1 | Cake | a | b | f |
| 2 | Coca | a | d | c |
| 3 | Ice | c | b | a |
| 4 | Wine | c | e | d |
| 5 | Salad | c | f | a |
| 6 | Water | d | e | f |
+------+-------+-------+-------+-------+
I want to write an sql statement to count all type that present in type1, type2, type3 so the result I want to get is
+------+------+
| type | count|
+------+------+
| a | 4 |
| b | 2 |
| c | 4 |
| d | 3 |
| e | 2 |
| f | 3 |
+------+------+
Assume that we don't exactly knew how many different types and number of column, so can you kindly guide me how to deal with this problem? Oh should I solve it in level programming language not the sql? I use php on Symfony2.
Thanks in advance,