Firebird Select Query using same field twice

Asked

Viewed 565 times

0

I have a field called patiente_id, I want to create a select +- like this

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

I don’t know it was clear, but I want to know the amount of items where patiente_id is equal to zero and when is different.

hugs.

2 answers

2


follow the consultation 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 catch your var like this $resultado['id0'] for id=0 and $resultado['idok'] for ids <> 0

if necessary with 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 the dia_query you exchange for your date field and the $date he your chosen date, Obs vc should treat the date appropriately for the query.

  • what date format you are saving ?

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`

Browser other questions tagged

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