Bonjour,Pourquoi cette requête renvoie-t-elle des résultats indésirables?
J'ai un problème avec cette requête:
SELECT
P.txt_nome AS Pergunta,
IP.nome AS Resposta,
COUNT(*) AS Qtd
FROM
tb_resposta_formulario RF
INNER JOIN formularios F ON
F.id_formulario = RF.id_formulario
INNER JOIN tb_pergunta P ON
P.id_pergunta = RF.id_pergunta
INNER JOIN tb_resposta_formulario_combo RFC ON
RFC.id_resposta_formulario = RF.id_resposta_formulario
INNER JOIN itens_perguntas IP ON
IP.id_item_pergunta = RFC.id_item_pergunta
WHERE
RF.id_formulario = 2
GROUP BY
P.txt_nome,
IP.nome
Ceci est le résultat réel de cette requête:
| Pergunta | Resposta | Qtd |
| Produits | Combo 1MB | 3 |
| Produits | Combo 2MB | 5 |
| Produits | Combo 4MB | 1 |
| Produits | Combo 6MB | 1 |
| Produits | Combo 8MB | 4 |
| Região | MG | 3 |
| Região | PR | 2 |
| Região | RJ | 3 |
| Região | SC | 1 |
| Região | SP | 5 |
Ce sont les résultats que j'attendais:
| Produto | Região | Qtd |
| Combo 1Mo | MG | 3 |
| Combo 2Mo | SP | 5 |
| Combo 4Mo | SC | 1 |
| Combo 6Mo | RJ | 1 |
| Combo 8MB | PR | 2 | J'utilise les opérateurs PIVOT et UNPIVOT mais le résultat n'est pas satisfaisant.
Quelqu'un at-il déjà fait face à cette situation avant? Avez-vous un aperçu que vous pouvez offrir?
Je l'ai déjà analysé ces liens:
- SQL Server 2005 Pivot on Unknown Number of Columns
- Transpose a set of rows as columns in SQL Server 2000
- SQL Server 2005, turn columns into rows
- Pivot Table and Concatenate Columns
- PIVOT in sql 2005
Att, Pelegrini