查询计数错误

编程入门 行业动态 更新时间:2024-10-25 07:24:48
本文介绍了查询计数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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'

更多推荐

查询计数错误

本文发布于:2023-11-04 12:21:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!