id - a_id - a_type
---------------------------
1 9 Granny Smith
2 9 Pink Lady
---------------------------
3 3 Pink Lady
4 3 Fuji
5 3 Granny Smith
---------------------------
6 7 Pink Lady
7 7 Fuji
8 7 Fuji
9 7 Granny Smith
Ok, assuming we have an Apple sql table like above; my question, is possible to have a result like below, with one query?
[0] => Array
(
[0] => a_id: 7
[1] => Pink Lady: 1
[2] => Granny Smith: 1
[3] => Fuji: 2
)
[1] => Array
(
[0] => a_id: 9
[1] => Granny Smith: 1
[2] => Pink Lady: 1
[3] =>
)
...
Thank's in advance!
PS: my own query is this:
SELECT a_type , a_id ,
COUNT(a_type) AS tot
FROM #apple
GROUP by a_id , a_type
HAVING tot > 0
ORDER BY a_type DESC
but this don't do what i need! it produce more than one a_id!