php - MySQL Count Where 子句问题

标签 php mysql

我有一个 PHP 表单,它有 3 个下拉菜单,使用户能够选择要传递给 MySQL select 语句的参数。我想根据所选条件返回记录总数。

我遇到的问题是结果返回几个总计而不是总计。

SELECT distinct count(membership_type) as total FROM members_main where membership_status like '%' and membership_type like '%' and 200_member like '%' group by membership_type

有人可以帮忙吗?

谢谢

约翰

最佳答案

从members_main中选择总数(membership_type),其中membership_status如“%”,membership_type如“%”,200_member如“%”

不要使用分组依据。当您使用 group by 子句时,您将获得每个 membership_type 的计数,这就是您获得多行的原因。

关于php - MySQL Count Where 子句问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17468922/

相关文章:

mysql - 将表连接到自身并仅返回匹配值的优化方式(也删除此行)

mysql - 不显示拥有多个实例的用户的平均值

php - 集成/迁移两个 CodeIgniter 应用程序。

php - 在 php 中加载 xml 文件 - 缺少访问权限?

php - 如何在 Elasticsearch 中获取没有大小的总记录数

php - Laravel 5 在服务器上显示空白页面但在本地工作

php - 在mysql中使用变量作为参数

php - WAMPSERVER php_memcache 扩展

php - 复杂查询+分页脚本

php - 在 wordpress 页面的选择标签中显示查询结果?