Count a pl/sql column

Asked

Viewed 82 times

-1

I am trying to count a column (minutes) as it is in the query:

SELECT distinct b.nr_atendimento
        ,to_char(dt_prescricao,'dd/mm/yyyy hh24:mi:ss') Prescricao
        ,to_char(a.dt_atualizacao,'dd/mm/yyyy hh24:mi:ss') Atualizacao
        ,trunc( mod(mod(a.dt_atualizacao-dt_prescricao,1)*24,1)*60 ) as Minutos
FROM    result_laboratorio a,
        prescr_procedimento c,
        prescr_medica b
WHERE  Trunc( LAST_DAY( b.dt_prescricao )) = Last_Day(:MES_REF)
    AND c.nr_prescricao  = a.nr_prescricao(+) 
    AND c.nr_sequencia = a.nr_seq_prescricao(+) 
    AND c.nr_prescricao  = b.nr_prescricao 
    AND b.cd_estabelecimento = '1'
    AND a.dt_atualizacao IS NOT NULL
ORDER BY nr_atendimento desc

I’m already adding up the hours and taking the minutes during the service, but I need to count the total minutes.

Upshot:

serve. Request Result Minutes

1727336 21/05/2021 08:42:00 21/05/2021 09:50:21 68

1727336 21/05/2021 08:42:00 21/05/2021 09:50:30 68

                             Total minutos: 136 

I want my query to make the sum total

  • I’m already adding up the hours and taking the minutes during the service, but I need to add the tatal minutes

  • Which database manager system? Which result is returning? What is the expected result?

  • Result: meet. Request Result Minutes 1727336 21/05/2021 08:42:00 21/05/2021 09:50:21 68
1727336 21/05/2021 08:42:00 21/05/2021 09:50:30 68 Total minutes:

  • Which database is using?

  • pl sql oracle Developer

1 answer

0

The result of your query does not match with the example query.

In the query there is no service field, but in the result yes, anyway I understand that what you need is a query similar to the query below, if really the example query is wrong please post the correct query:

SELECT ATENDIMENTO  AS ATENDIMENTO,
       SUM(X.HORAS)   AS TOTAL_HORAS,
       SUM(X.MINUTOS) AS TOTAL_MINUTOS
FROM (

SELECT ATENDIMENTO, 
      START_DATE,
      END_DATE, 
      TRUNC( 24* (END_DATE - START_DATE))           AS HORAS,
      ( MOD(MOD(END_DATE - START_DATE,1)*24,1)*60 ) AS MINUTOS
 FROM T
 
) X
GROUP BY ATENDIMENTO
  • Thanks for informing about the query, I edited, but I can’t get to add the total minutes.

  • You only need to return the total value in minutes?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.