0

i have Table PRICE

CodePrice  CodeClient  TheZone Tempo W_Begin W_End Price
A_0_49       88989       1       1      0      49   20
A_50_99      60000       1       1      50     99   10
B_0_49       88989       2       1      0      49   30
C_0_49       50000       3       4      0      49   40

Table Ordre

  NoID  CodeClient    Cp   Agence  TheZone Tempo Weight 
    01      88989     44   bidon      1      1     12
    02      60000     49   toto       2      2     10
    03      60000     49   bigoi      1      1     56
    04      88989     49   titi       3      3     8
    05      50000     44   bidon      1      1     5

How can i show the result like this:

CodePrice   TheZone Tempo W_Begin W_End  SUm_Weight  SUM_Price  CountIDOrdre  CP   Agence
  A_0_49        1       1      0      49       17         40          2         44    bidon
  A_50_99       1       1      50     99       56         10          1         49    bigoi
  B_0_49        2       1      0      49       0          0           0         null  null
  C_0_49        3       4      0      49       0          0           0         null  null

in 1 SQL Syntax (1 Step).

Nowdays i make it in 2 step

SELECT CodePrice
      ,CodeClient
      ,TheZone         
      ,Tempo   
      ,W_Begin
      ,W_End
      ,Price          
  FROM PRICE
  LEFT JOIN T_TARIF_ZONE ON PRICE.ZONE = T_TARIF_ZONE.NO_ID     
  LEFT JOIN CLIENT ON PRICE.CodeClient= CLIENT.CODE_CL     

  WHERE CodeClient= @NO_CLIENT AND TheZone = @ZONE AND UNITE = @UNITE 
  AND (Tempo   IN (SELECT ParsedString From dbo.ParseStringList(@ModLiv)))

  ORDER BY MONTANT

after i select the price, now i can group the ordre on each price depends on Weight, zone, and another variable

SELECT count(NoID) as LVId            
      ,sum(Weight)as Tot_Poids        
      ,sum(Price) as Tot_Prix      

  FROM [Ordre]
  WHERE Weight>= @TR_DEB AND Weight<= @TR_FIN AND LE_ZONE = @LE_ZONE AND ENLEV_UNITE = @ENLEV_UNITE 
        AND DATE_CLOTURE >= @Date_Deb AND DATE_CLOTURE <= @Date_Fin AND STATUT_LV = 2 AND FACTURATION = @FACTURATION

  HAVING count([NOID]) > 0  
4

0 回答 0