我有一个 mysql 数据库,结构如下:
表交易
:
id paymentid clientid status
------------------------------
1 001 12345 0
2 002 11223 1
3 003 12345 4
4 004 12345 4
在 mysql 中运行查询以获取某个 clientid 状态为 4 的付款的次数的最有效方法是什么?
喜欢:
select clientid, count(*)
where status = 4
但仅返回特定 clientid 的计数。
最佳答案
如果您想按特定客户端进行过滤,只需为 clientId
添加 WHERE
过滤器即可。如果没有,那么您可以删除 和 clientid = 12345
:
select clientid, count(*)
from transactions
where status = 4
and clientid = 12345
GROUP BY clientId;
关于mysql - 使用特定变量计算同一查询中的两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16824476/