Nikhil Musale
Nikhil Musale

Reputation: 332

count number of rows using where

m new in mysql

here is my table

enter image description here

now i want to count "count_id" where count of 'questionID' greater than 2

Upvotes: 1

Views: 61

Answers (7)

Giles
Giles

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

Thorsten Kettner
Thorsten Kettner

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

Brahmanand Choudhary
Brahmanand Choudhary

Reputation: 21

SELECT COUNT(count_id) FROM table_name WHERE questionID > 2

Upvotes: 0

Hereblur
Hereblur

Reputation: 2164

If you want to count unique ID:

select count(DISTINCT count_id) from table_name where questionID > 2

Upvotes: 0

Ronak Shah
Ronak Shah

Reputation: 1549

select  count(count_id) from yourtable where questionID > 2

Upvotes: 0

user262503
user262503

Reputation: 103

select count(Count_ID),QuestionID,SurveyId from table 
where QuestionID>2
group by QuestionID,SurveyID

Upvotes: 0

yassine__
yassine__

Reputation: 393

Try this :

SELECT COUNT(count_id) FROM myTable WHERE questionID > 2

Upvotes: 1

Related Questions