Ticket:
id_ticket |id_ticket_category |
----------|-------------------|
1 |8 |
2 |8 |
3 |13 |
Category:
id_category |id_parent |label |id_category_type |
------------|----------|----------------------------------|-----------------|
1 |-1 |Demande d'information |1 |
2 |-1 |Réclamation |1 |
3 |1 |Autre |2 |
4 |1 |Mairie |2 |
5 |1 |Stationnement |2 |
6 |2 |Autre |2 |
8 |3 |Autre |3 |
9 |4 |Réservation de salle |3 |
10 |4 |Autre |3 |
11 |5 |Horaires de stationnement |3 |
12 |5 |Autre |3 |
13 |6 |Autre |3 |
16 |7 |Autre |3 |
Notice that the id_ticket_category
column in the Ticket
table refers to the id_category
in the Category
table.
I want to return the count and concat
row who i have a id_ticket_category (id_category)
with id_parentof element.
Example:
For the id_ticket_category = 8
i look on the Category
table
id_category |id_parent |label |id_category_type |
------------|----------|----------------------------------|-----------------|
8 |3 |Autre |3 |
I look is id_parent
is not equal at -1
id_category |id_parent |label |id_category_type |
------------|----------|----------------------------------|-----------------|
3 |1 |Autre |2 |
I look is id_parent is not equal at -1
id_category |id_parent |label |id_category_type |
------------|----------|----------------------------------|-----------------|
1 |-1 |Demande d'information |1 |
id_parent
is equal -1
i print my result
Category |count|
-------------------------|-----|
Autre-Demande Information| 2 |
Actually i have this request:
SELECT CONCAT(c.label, '-', parents.label), c.id_parent
FROM Category c INNER JOIN
(SELECT id_category AS id, label FROM category c WHERE id_parent = -1) AS parents
ON parents.id = c.id_parent
WHERE c.id_category_type < 3
ORDER BY c.id_category_type;
so does anyone know how to improve this?