dimanche 3 juillet 2016

php sql query without foreach simple way

I would like to make some statisctics. My database looks like that:

+----+------------+------------+------------+--------------+
| id | value1     | value2     |  value 3   |     year     |
+----+------------+------------+------------+--------------+
|  1 | something1 | something3 | something5 |         2016 |
|  2 | something2 | something3 | something6 |         2015 |
|  3 | something1 | something4 | something5 |         2014 |
|  4 | something1 | something4 | something6 |         2016 |
|  5 | something2 | something3 | something5 |         2014 |
+----+------------+------------+------------+--------------+

And my question is how to construct as simple as possible query or queries which counts values and returns an array which has structure below?

[0] =>
    ['year'] => 2014
    ['value1'] =>
        ['something1'] => 1
        ['something2'] => 1
    ['value2'] =>
        ['something3'] => 1
        ['something4'] => 1
    ['value3'] =>
        ['something5'] => 2
[1] =>
    ['year'] => 2015
    ['value1'] =>
        ['something2'] => 1
    ['value2'] =>
        ['something3'] => 1
    ['value3'] =>
        ['something6'] => 1
[2] =>
    ['year'] => 2016
    ['value1'] =>
        ['something1'] => 2
    ['value2'] =>
        ['something3'] => 1
        ['something4'] => 1
    ['value3'] =>
        ['something5'] => 1
        ['something6'] => 1

Aucun commentaire:

Enregistrer un commentaire