как получить данные до 8:30, с 8:30 до 9:00 и после 9:00 - PullRequest
0 голосов
/ 15 мая 2018

как получить данные до 8:30, с 8:30 до 9:00 и после 9:00

 select distinct  emp.emc_name 
    Count(select count(max(s.SAD_DATE)) from Shift s1 where s1.EM_CODE=s.EM_CODE and EXTRACT(HOUR FROM CAST(s.SAD_DATE AS TIMESTAMP)) < 8:30  ) Before8.30am  ,
    Count(select count(max(s.SAD_DATE)) from Shift s1 where s1.EM_CODE=s.EM_CODE and EXTRACT(HOUR FROM CAST(s.SAD_DATE AS TIMESTAMP)) between 8:30 and 9  ) 8.30amTo9am,
    Count(select count(max(s.SAD_DATE)) from Shift s1 where s1.EM_CODE=s.EM_CODE and EXTRACT(HOUR FROM CAST(s.SAD_DATE AS TIMESTAMP)) > 9  ) After9,
    from Shift s,emply emp
    where s.EM_CODE = emp.EM_CODE and emp.DP_CODE in  ('C019') and s.SAC_INOUT=1
    and s.SAD_DATE between '01-mar-2018' and '31-mar-2018'
    order by emp.EMC_NAME
    group by emp.EMC_NAME 

1 Ответ

0 голосов
/ 15 мая 2018

Что-то вроде:

SELECT              -- You don't need both DISTINCT and GROUP BY
       emp.emc_name, 
       COUNT(
         CASE
         WHEN SAD_DATE <  TRUNC( SAD_DATE ) + INTERVAL '08:30' HOUR TO MINUTE
         THEN 1
         END
       ) "Before8.30am",
       COUNT(
         CASE
         WHEN SAD_DATE >= TRUNC( SAD_DATE ) + INTERVAL '08:30' HOUR TO MINUTE
         AND  SAD_DATE <  TRUNC( SAD_DATE ) + INTERVAL '09:00' HOUR TO MINUTE
         THEN 1
         END
       ) "8.30amTo9am"
       COUNT(
         CASE
         WHEN SAD_DATE >= TRUNC( SAD_DATE ) + INTERVAL '09:00' HOUR TO MINUTE
         THEN 1
         END
       ) "After9"
from   Shift s
       INNER JOIN emply emp
       ON ( s.EM_CODE = emp.EM_CODE ) -- Use ANSI Joins not legacy Oracle joins
where  emp.DP_CODE in  ('C019')
and    s.SAC_INOUT = 1
and    s.SAD_DATE between DATE '2018-03-01' and DATE '2018-03-31'
                          -- Use a date literal and not implicit conversion of a string
group by emp.EMC_NAME  order by 1
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...