查询计数错误 [英] wrong count in query

查看:64
本文介绍了查询计数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其结构如下:

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'

这篇关于查询计数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆