| 12
 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
 
 |  
CREATE VIEW xxxxxxxx
AS
   SELECT crb.compteur_id,
          crb.type_pt_id,
          min (crb.datepoint)
             AS dtmin,
          max (crb.datepoint)
             AS dtmax,
          count (*)
             AS [count],
          max (version)
             AS maxversion,
          (SELECT TOP 1 datepoint
           FROM codap.gtm_crb10mn
           WHERE version = max (crb.version) AND type_pt_id = crb.type_pt_id)
             AS dtmaxversion,
          max (crb.dateversion)
             AS dtlastupdate
   FROM xxxxxxx
   where crb.version =
             (SELECT max (crb2.version)
              FROM xxxxxxx
              WHERE     crb2.datepoint = crb.datepoint
                    AND crb2.type_pt_id = crb.type_pt_id
                    AND crb2.compteur_id = crb.compteur_id)
   GROUP BY crb.type_pt_id, crb.compteur_id |