Advertisement
omegastripes

fetch_onto_scale_on_criteria

Jul 23rd, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.40 KB | None | 0 0
  1. -- fetch_onto_scale_on_criteria
  2. -- MS ACCESS JET
  3. -- items table: id, t (process time), v (value), prop (property)
  4. -- scale view: n (interval number on chart time axis), a (from), b (upto)
  5. SELECT scale.n,
  6.        scale.a,
  7.        scale.b,
  8.        r0.v0,
  9.        rA.vA,
  10.        rB.vB,
  11.        rC.vC
  12. FROM
  13. (((scale
  14.         LEFT JOIN
  15.      (SELECT n,
  16.              SUM(v) AS v0
  17.       FROM
  18.         (SELECT items.v,
  19.                 scale.n
  20.          FROM items,
  21.               scale
  22.          WHERE items.t>=scale.a
  23.            AND items.t<scale.b)
  24.       GROUP BY n) AS r0 ON scale.n=r0.n)
  25.   LEFT JOIN
  26.     (SELECT n,
  27.             SUM(v) AS vA
  28.      FROM
  29.        (SELECT items.v,
  30.                scale.n
  31.         FROM items,
  32.              scale
  33.         WHERE items.t>=scale.a
  34.           AND items.t<scale.b
  35.           AND items.prop='a')
  36.      GROUP BY n) AS rA ON scale.n=rA.n)
  37.  LEFT JOIN
  38.    (SELECT n,
  39.            SUM(v) AS vB
  40.     FROM
  41.       (SELECT items.v,
  42.               scale.n
  43.        FROM items,
  44.             scale
  45.        WHERE items.t>=scale.a
  46.          AND items.t<scale.b
  47.          AND items.prop='b')
  48.     GROUP BY n) AS rB ON scale.n=rB.n)
  49. LEFT JOIN
  50.   (SELECT n,
  51.           SUM(v) AS vC
  52.    FROM
  53.      (SELECT items.v,
  54.              scale.n
  55.       FROM items,
  56.            scale
  57.       WHERE items.t>=scale.a
  58.         AND items.t<scale.b
  59.         AND items.prop='c')
  60.    GROUP BY n) AS rC ON scale.n=rC.n;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement