Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.10 KB | None | 0 0
  1. SELECT
  2.     *,
  3.     ROUND(a.totalQty / a.totalHours, 2) as AVERAGE
  4. FROM
  5.     (
  6.     select
  7.         l.created_by,
  8.         dur.duration/ 3600 as totalHours,
  9.         sum(qty.qty) as totalQty
  10.     from
  11.         fahasa_suborder_log l
  12.     JOIN (
  13.     SELECT created_by, sum(duration) as duration from  (
  14.         SELECT
  15.             created_by,
  16.             duration,
  17.             created_at
  18.         FROM
  19.             fahasa_suborder_log l
  20.         where
  21.             l.`action` = 'picking'
  22.             and date(l.created_at) >= '2019-8-1'
  23.             and DATE_FORMAT(l.created_at, '%H:%i:%s') BETWEEN TIME_FORMAT('8:00:00', '%H:%i:%s') AND TIME_FORMAT('10:00:00', '%H:%i:%s')
  24.             and l.duration is not null
  25.         group by
  26.             created_by,created_at
  27.             ) a group by a.created_by
  28.             ) dur on
  29.         l.created_by = dur.created_by
  30.     JOIN (
  31.         SELECT
  32.             suborder_id,
  33.             sum(qty) as qty
  34.         FROM
  35.             fahasa_suborder_item
  36.         group by
  37.             suborder_id) qty on
  38.         qty.suborder_id = l.suborder_id
  39.     where
  40.         l.`action` = 'picking'
  41.         and date(l.created_at) >= '2019-8-1'
  42.         and DATE_FORMAT(l.created_at, '%H:%i:%s') BETWEEN TIME_FORMAT('8:00:00', '%H:%i:%s') AND TIME_FORMAT('10:00:00', '%H:%i:%s')
  43.         and l.duration is not null
  44.     group by
  45.         l.created_by ) a;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement