计算使用where的行数

时间:2014-09-18 10:58:34

标签: mysql sql

m mysql中的新内容

这是我的表

enter image description here

现在我想计算" count_id"其中' questionID'大于2

7 个答案:

答案 0 :(得分:1)

试试这个:

SELECT COUNT(count_id) FROM myTable WHERE questionID > 2

答案 1 :(得分:0)

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

答案 2 :(得分:0)

您也可以尝试以下声明:

select count(count_id) CountOfID,count_id from mytable 
where questionID > 2 group by count_id;

答案 3 :(得分:0)

select  count(count_id) from yourtable where questionID > 2

答案 4 :(得分:0)

如果您想要计算唯一ID:

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

答案 5 :(得分:0)

SELECT COUNT(count_id)FROM table_name WHERE questionID> 2

答案 6 :(得分:0)

按Count_ID分组并计算他们不同的问题。留在那些有两个以上的人。然后计算你得到多少个ID。

select count(*)
from
(
  select count_id
  from mytable
  group by count_id
  having count(distinct questionid) > 2
) x;

编辑:如果count_id + questionid恰好是该表的唯一,则可以将count(distinct questionid)替换为count(*)