Firebird Query Select using same field twice

0

I have a field called patient_id, I want to create a select + - so

select count(paciente_id where = 0), count(paciente_id where <> 0) from agenda

I do not know, but I want to know the amount of items where patient_id is equal to zero and when it is different.

Hugs.

    
asked by anonymous 06.10.2016 / 22:56

2 answers

2

follows the query that should work

SELECT (select count(paciente_id) from agenda where paciente_id='0') as id0, (select count(paciente_id) from agenda where paciente_id<>'0') as idok from agenda;

no result just get your var so $resultado['id0'] to id = 0 and $resultado['idok'] to ids <> 0

If you need a date

SELECT (select count(paciente_id) from agenda where paciente_id='0' and dia_consulta='$data') as id0, (select count(paciente_id) from agenda where paciente_id<>'0' and dia_consulta='$data') as idok from agenda;

where query_day you trade by its date field and date has its date chosen, OBs you should treat the date appropriately for the query.

    
06.10.2016 / 23:20
1

You can use a case:

select 

count(case when(paciente_id='0') then paciente_id else null end)  as id0

, count(case when(paciente_id<>'0') then paciente_id else null end) as idok

from agenda'
    
22.11.2016 / 20:03