Reputation: 332
m new in mysql
here is my table
now i want to count "count_id" where count of 'questionID' greater than 2
Upvotes: 1
Views: 61
Reputation: 1667
You can also try the statement below:
select count(count_id) CountOfID,count_id from mytable
where questionID > 2 group by count_id;
Upvotes: 0
Reputation: 94884
Group by Count_ID and count their distinct questions. Stay with those that have more than two. Then count how many IDs you got.
select count(*)
from
(
select count_id
from mytable
group by count_id
having count(distinct questionid) > 2
) x;
EDIT: If count_id + questionid happen to be unique for the table, you can replace count(distinct questionid)
with count(*)
.
Upvotes: 0
Reputation: 21
SELECT COUNT(count_id) FROM table_name WHERE questionID > 2
Upvotes: 0
Reputation: 2164
If you want to count unique ID:
select count(DISTINCT count_id) from table_name where questionID > 2
Upvotes: 0
Reputation: 103
select count(Count_ID),QuestionID,SurveyId from table
where QuestionID>2
group by QuestionID,SurveyID
Upvotes: 0
Reputation: 393
Try this :
SELECT COUNT(count_id) FROM myTable WHERE questionID > 2
Upvotes: 1