Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

jramos

Select encadeado

Recommended Posts

Bom pessoal,

 

Tenho tres consultas distintas que so muda a faixa de hora, porem quero que ela seja um unico select, exemplo:

 

Data     | Cafe | Almoço | Jantar
21/12/12 |  15  |   62   |   36

 

 

Esses sao os comandos separados:

select CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) AS Data, count(mov_datahora) AS CAFE from log_credencial
where mov_datahora between '20121201' and '20121216'
and mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) > '05:30'
AND mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) < '08:00'
and eqpi_numero = 2
group by CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime)

 

select CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) AS Data, count(mov_datahora) AS ALMOÇO from log_credencial
where mov_datahora between '20121201' and '20121216'
and mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) > '10:30'
AND mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) < '14:00'
and eqpi_numero = 2
group by CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime)

 

select CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) AS Data, count(mov_datahora) AS JANTAR from log_credencial
where mov_datahora between '20121201' and '20121216'
and mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) > '18:00'
AND mov_datahora - CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) < '20:00'
and eqpi_numero = 2
group by CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime)

 

Alguem pode me ajudar?

Compartilhar este post


Link para o post
Compartilhar em outros sites
select sum(case when CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) < '12:00' 
        then 1 else 0 end) cafe,
      sum(case when CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) between '12:00' and '17:59' 
        then 1 else 0 end) almoco,
      sum(case when CAST(FLOOR(CAST(mov_datahora AS float)) AS datetime) >= '18:00' 
        then 1 else 0 end) jantar
from log_credencial
where mov_datahora between '20121201' and '20121216'
and eqpi_numero = 2

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.