sql - Mysql Count Query with value condition -


Suppose I have the table student as described below:

 + - ---------------- + ----------------- + ------------- - - + |  ID  |  PaperID  |  readFlag  | + ----------------- + ----------------- + ------------- ---- + | 1 | 1 | 1 | + ----------------- + ----------------- + ------------- ---- + | 2 | 2 | 1 | + ----------------- + ----------------- + ------------- ---- + | 3 | 3 | 1 | + ----------------- + ----------------- + ------------- ---- + | 4 | 1 | 0 | + ----------------- + ----------------- + ------------- ---- + | 5 | 2 | 1 | + ----------------- + ----------------- + ------------- ---- + | 6 | 3 | 1 | + ----------------- + ----------------- + ------------- ---- + | 7 | 4 | 1 | + ----------------- + ----------------- + ------------- ---- + 

I want to know how many paperID have a record or two record, where both records have readFlag set < Code> 1 .

For example, Answer 3 ( paper id 's 2, 3, and 4).

How do I write a question to do this?

EDIT:

I do not want to use subclass, because I have millions of records and it takes a lot of time to execute the sub-section.

Try this:

  SELECT COUNT (DISTINCT (paper ID)) Student is not in paper (selection from student (paper ID) where readFlag = 0); Choose from student (select number (paper ID)) - (Student ID (PaperID)) from where readFlag =  0);  

Comments