bonjour à tous,
Je dipose d'une requete sql que j'ai "simplifié" j'ai enlevé les champs qui ne m'intessessait pas .
Ci-dessus ma requete.
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 SELECT (select coalesce (sum (ttotfichado.Tiempopasado),0) from ttotfichado where ttotfichado.hayabono<> 1 and (NOT (ttOTFichado.RepartoPendiente = 0 AND ttOTFichado.FichajeContraOT > 0) or ttOTFichado.RepartoPendiente IS NULL) AND ttOTIntervencion.Emp = ttOTFichado.Emp AND ttOTIntervencion.Numinterno = ttOTFichado.Numinterno AND ttOTIntervencion.Intervencion = ttOTFichado.Intervencion and ttotfichado.fecha <= '12-1-2011 23:59:59.000') as tt, Count(DISTINCT ttOTCab.NumOT), SUM(case tipocab when 0 then case tipolinea when 1 then case ttOTIntervencion.esabono when 1 then (-1 * ttotlinea.PrecioCosteMedio * coalesce (ttotcargolinea.cantidadhoras,ttotlinea.cantidadhoras)) else (ttotlinea.PrecioCosteMedio * coalesce (ttotcargolinea.cantidadhoras,ttotlinea.cantidadhoras)) end else 0 end else 0 end) as ImpPCPMrec, tgtaller.descrip as atelier, tgempresa.razon as societe FROM ttoTCab inner join tgempresa on ttotcab.emp = tgempresa.emp inner join tgtaller on ttotcab.emp = tgtaller.emp and ttotcab.taller = tgtaller.taller INNER JOIN ttOTIntervencion ON ttOTCab.Emp = ttOTIntervencion.Emp AND ttOTCab.NumInterno = ttOTIntervencion.Numinterno INNER JOIN ttOTLinea ON ttOTIntervencion.Emp = ttOTLinea.Emp AND ttOTIntervencion.Numinterno = ttOTLinea.NumIntOT AND ttOTIntervencion.Intervencion = ttOTLinea.NumIntIntervencion INNER JOIN ttSeccion ON ttOTCab.Seccion = ttSeccion.Seccion INNER JOIN ttSeccion seccion ON ttOTIntervencion.Seccion = seccion.Seccion LEFT OUTER JOIN TTrecepcionista ON ttOtCab.emp = TTrecepcionista.emp and ttOtCab.taller = TTrecepcionista.taller and ttOtCab.recepcionista = TTrecepcionista.recepcionista LEFT OUTER JOIN Tgmarca ON ttOtCab.marca = tgmarca.marca LEFT OUTER JOIN ttOTCargoLinea ON ttOTLinea.Emp = ttOTCargoLinea.Emp AND ttOTLinea.NumIntOT = ttOTCargoLinea.NumIntOT AND ttOTLinea.NumIntIntervencion = ttOTCargoLinea.NumIntIntervencion AND ttOTLinea.LineaItem = ttOTCargoLinea.LineaItem LEFT OUTER JOIN ttOTCargoInt on ttOTCargoLinea.Emp = ttotcargoint.emp AND ttOTCargoLinea.NumIntOT = ttotcargoint.Numintot AND ttOTCargoLinea.NumIntIntervencion = ttotcargoint.numintintervencion AND ttOTCargoLinea.NumIntcargo = ttotcargoint.numintcargo LEFT OUTER JOIN ttotcargo on ttotcargoint.emp=ttotcargo.emp and ttotcargoint.NumIntOT=ttotcargo.NumInterno and ttotcargoint.NumIntCargo=ttotcargo.Cargo LEFT OUTER JOIN ttgrupocargo on ttOTCargo.grupocargo = ttgrupocargo.grupo LEFT OUTER JOIN tgGrupoCont ON ttOTLinea.GrupoCont = tgGrupoCont.GrupoCont LEFT OUTER JOIN tgMarca MarcaLinea ON ttOTLinea.Marca = MarcaLinea.Marca LEFT OUTER JOIN tacategoriapieza ON ttotlinea.marca = tacategoriapieza.marca and ttotlinea.codigocategoria = tacategoriapieza.codigo LEFT OUTER JOIN ttotstatus ON ttOTCab.statusencurso = ttotstatus.Codigo WHERE (ttotcab.emp='002' ) and (ttotintervencion.hayfactura = 0 ) and (ttotcab.taller='20' ) and (ttOTCab.Anulada = 0) and (ttOTLinea.Anulada = 0) AND (ttOTCab.FechaAperturaOT <= '12-1-2011 23:59:59.000' ) AND ( ttOTLinea.FechaAlta <= '12-1-2011 23:59:59.000' or ttotlinea.tipocab =1 ) and (ttotlinea.tipocab <> 2) and (ttOTCab.Status = 30 ) and (ttotlinea.cantidadhoras <> 0 or ttotlinea.almservido <> 1) group by tgempresa.razon, tgtaller.descrip, ttOTIntervencion.Emp, ttOTIntervencion.Numinterno, ttOTIntervencion.Intervencion
J'arrive a récupérer le nom entreprise , atelier, plus le nombre de ligne (count).
Mais je n'arrive pas faire une somme d'une somme.
Ci-dessous la partie de la requête qui m'intéresser:
Ceci fait la somme dans une table. Et ce que je voudrait c'est la somme de cette somme. pour que cela sort comme ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
 1
2
3
4
5
6
7
8
9 (select coalesce (sum (ttotfichado.Tiempopasado),0) from ttotfichado where ttotfichado.hayabono<> 1 and (NOT (ttOTFichado.RepartoPendiente = 0 AND ttOTFichado.FichajeContraOT > 0) or ttOTFichado.RepartoPendiente IS NULL) AND ttOTIntervencion.Emp = ttOTFichado.Emp AND ttOTIntervencion.Numinterno = ttOTFichado.Numinterno AND ttOTIntervencion.Intervencion = ttOTFichado.Intervencion and ttotfichado.fecha <= '12-1-2011 23:59:59.000') as tt,
Alors que la actuellement cela sort comme ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part entreprise1|atelier|nbr 88| Somme total.
Comment réaliser ceci?
Code : Sélectionner tout - Visualiser dans une fenêtre à part 
 1
2
3
4
5
6 entreprise1|atelier1|nbr 1| som1 entreprise1|atelier1|nbr 1| som2 entreprise1|atelier1|nbr 1| som3 entreprise1|atelier1|nbr 1| som4 entreprise1|atelier1|nbr 1| som5 etc...
Merci d'avance pour votre aide
guigui69
		
		
        


   


  Répondre avec citation


 




 
 
 
 

Partager