Optimisation de requête SQL
Bonjour, je suis actuellement en galère (: J'ai pondu un code en Visual Basic qui donne ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| entiter = CStr(CType(Cbbox_choientite.SelectedItem, ListItem).Value)
Dim resultSQL4 As DataView = SelectBDD("SELECT id AS id_ticket FROM glpi_tickets WHERE entities_id = " & entiter & "")
If resultSQL4.Count >= 0 Then
For Each rst As DataRowView In resultSQL4
id_ticket = rst("id_ticket")
Dim resultSQL3 As DataView = SelectBDD("SELECT id, actiontime AS temptelephone FROM glpi_tickettasks WHERE tickets_id = " & id_ticket & " and taskcategories_id in (1 ,0)")
If resultSQL.Count >= 0 Then
For Each rst4 As DataRowView In resultSQL3
addittiontelephone = addittiontelephone + rst4("temptelephone")
Next
End If
Dim resultSQL5 As DataView = SelectBDD("SELECT id, actiontime AS tempsite FROM glpi_tickettasks WHERE tickets_id = " & id_ticket & " and taskcategories_id = 2")
If resultSQL.Count >= 0 Then
For Each rst2 As DataRowView In resultSQL5
addittionsite = addittionsite + rst2("tempsite")
Next
End If
Next
End If |
Je fais donc 3 requêtes SQL, ce qui est assez lourd. J'aimerais n'en faire qu'une seul...
Mes compétences en SQL ne me le permettent malheureusement pas...
Du coup je viens demandé de l'aider de votre coté, ce que j'ai réussis à pondre donne ça :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| select id AS id_ticket, tpsTotal.tpsTel
from table
LEFT OUTER JOIN (
select id , SUM(temptelephone) As tpstel, SUM(tempSite) As tpsSite
from (
SELECT id,
CASE WHEN taskcategories_id in (0, 1) then actiontime else 0 end AS temptelephone,
CASE WHEN taskcategories_id in (2) then actiontime else 0 end AS tempSite
FROM glpi_tickettasks
WHERE tickets_id=5555
and taskcategories_id in (0, 1, 2)
) sqlDetail
group by id
) tpsTotal ON tpsTotal.id=table. |
Mais ça ne fonctionne pas... SVP help (: