tags:

views:

98

answers:

2

i have table with name sample in my database it has threecolumns namely words,D1,D2 and it has some data like below

Words      D1     D2  D3
pleasure    1      0   1
question    0      0   0         
answer      0      1   1
request     1      0   0
scount      1      0   0

so now i want to calculate parameter N00 which means scount=0 and also it should check where 0 exists in D1 and D2 so here for "question" D1=0 D2=0 and scount=0 so the result should be 2 because scount=0 and D1=0 , scount=0 and D2=0 this both satisfy so result is 2 i need sql query fro this please help advance thanks.

+2  A: 

If I'm reading correctly you want to know how many records there are with scount = 0 and either D1 or D2 = 0, that's a query like this:

SELECT COUNT(*) as N00 FROM mytable WHERE scount = 0 AND (D1 = 0 OR D2 = 0)

on second pass I think you're trying to count conditions satisfied, that is, +1 when D1 = 0 and +1 when D2 = 0, but only where scount = 0, that's something like this:

SELECT (IF(D1=0,1,0)+IF(D2=0,1,0)) as N00 WHERE scount = 0
Mark E
thanks for your reply im sorry scount is row not column please check the post i have saved edits
@vj4u making scount a row makes your conditions too inconsistent for me to parse. are you computing a value for each row? if so please add a fake column to show what the value should be. if not, please try to clarify how N00 depends on all rows. Where does D3 come into play?
Mark E
A: 

Your question doesn't add up. You act as if scount is a column but it is a row. And tbh your question is not making sense. Could you perhaps split this up in separate cases like:

A: (D1 = 0) AND (D2 = 0)  -> N00 = X 
B: (D1 = 0) AND (D2 = 1)  -> N00 = Y 

I don't have any idea how to fit in scount in these cases. You cant say the following:

C: (D1 = 0) AND (D2 = 0) AND (scount = 1) -> N00 = Z

This isn't possible because scount is in a different row and has no relation to this row at all.

Sjuul Janssen