Test Foro de elhacker.net SMF 2.1

Programación => Desarrollo Web => Bases de Datos => Mensaje iniciado por: Reent en 2 Septiembre 2020, 11:26 AM

Título: SQL if statement en un counter
Publicado por: Reent en 2 Septiembre 2020, 11:26 AM
Muy buenas estoy intentando hacer que un counter se multiplique si el tramaño de un row es igual a x ejemplo:

Código (sql) [Seleccionar]
select art.art_id, histkomm.cnt , count(decode(lhmd.abmz, 600, 2, 1))/*aqui necesito que el counter sea dos, si es el tamaño "x" y uno, si no lo es.*/, sysdate
   from lhm, art, sektor,lhmdef lhmd, (select hst.artnr artnr,  count(*) cnt
                                       from  historie_v hst
                                       where hst.created > sysdate-90
                                       and hst.typ_id =102
                                       and hst.lagnr=13 group by  hst.artnr ) histkomm
   where histkomm.artnr = art.artnr
   and art.art_id = sektor.art_id (+)
   and lhm.lhm_id = sektor.lhm_id
   and lhm.lhmdef_id = lhmd.lhmdef_id
   and lhm.lhmstat=1
   and lhm.lag_id=13
   and nvl(lhm.auftr_id, 0)=0
   group by art.art_id, histkomm.cnt
   order by 3 desc;


Por el momento el counter hace su trabajo bien pero no me funciona hacer lo que quiero.

un saludo!
Título: Re: SQL if statement en un counter
Publicado por: Carloswaldo en 1 Octubre 2020, 22:17 PM
No entiendo muy bien lo que quieres lograr, ¿pretendes que el COUNT cuente como 2 registros si el valor en cierta columna equivale a x? Si es así mejor usas un SUM ¿no? Así te va a sumar lo que sea que te devuelva el DECODE.