本文介绍了查询计数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,其结构如下:
I have a table whose structure is as follows:
id int userid int status enum ('pending','approved') dop datetime数据为:
id userid status dop 1 24 pending 2011-02-14 06:41:32 2 24 pending 2011-02-15 23:02:45当我触发以下查询时:
SELECT count( userid ) FROM t1 WHERE STATUS = 'pending' GROUP BY userid这让我算为"2",这是错误的,谁能告诉我这是怎么回事?以及如何获得真实计数为1
It's giving me count as '2', which is wrong, can anyone tell me what's wrong here? and how to get real count as 1
推荐答案在计数之后执行group by语句.改用它:
The group by statement is executed after the count. Use this instead:
SELECT count( DISTINCT userid ) FROM t1 WHERE STATUS = 'pending'更多推荐
查询计数错误
发布评论