hukuto7750
hukuto7750

Reputation: 149

mysql select counts by if else condition

i have a table named cq500_all(to record diffrent doctor feedback) now i want know counts when condition status is field dr_1_finish and field dr_2_finish value is all fill 1

and

when field dr_1 different dr_2 (like dr_1=1 and dr_2=0,or dr_1=0 and dr_2=1 )

cause i want to know two doctors feedback counts (when different doctor's feedback on jpg)

for example image show CQ500-CT-1_36_08.jpg and CQ500-CT-1_36_09.jpg is match my select counts it will be two (select counts result) how to make the query on mysql? enter image description here

Upvotes: 0

Views: 30

Answers (2)

Devsi Odedra
Devsi Odedra

Reputation: 5322

You can count as

select count(*) as total
from cq500_all
where dr_1_finish = 1 and dr_2_finish = 1 and dr_1 != dr_2

You will got result in total

Upvotes: 1

Willis Blackburn
Willis Blackburn

Reputation: 8204

Pretty much just the way you've described it:

select *
from cq500_all
where dr_1_finish = 1 and dr_2_finish = 1
and dr_1 != dr_2

or (if dr_1 or dr_2 might not be just 0 and 1):

select *
from cq500_all
where dr_1_finish = 1 and dr_2_finish = 1
and ((dr_1 = 1 and dr_2 = 0) or (dr_1 = 0 and dr_2 = 1))

Upvotes: 1

Related Questions