我可以从表中获取特定字段的计数结果吗?例如我正在使用此查询,
select id,retailer,email from tab
我得到了结果集,
1 ret1 test1@test.com
2 ret2 test1@test.com
3 ret3 test1@test.com
4 ret1 test2@test.com
5 ret2 test2@test.com
6 ret6 test2@test.com
我需要的是(test1@test.com)数量是明智的3倍。感谢。
答案 0 :(得分:2)
这将为您提供该表中所有电子邮件地址的计数:
SELECT email, COUNT(*) FROM tab GROUP BY email;
如果您只想获得一个特定的计数,请使用:
SELECT COUNT(*) FROM tab WHERE email = 'test@example.com';
答案 1 :(得分:0)
计算一封电子邮件:
select count(id)
from tab
where email = 'test1@test.com'
或计算所有电子邮件值:
select email, count(email)
from tab
group by email
答案 2 :(得分:0)
将所有电子邮件分组在一起计算:
SELECT email , COUNT(*) AS 'count' FROM `tab` GROUP BY email
如果您只想查找一个电子邮件地址:
SELECT email , COUNT(*) AS 'count' FROM `tab` WHERE email = 'test@example.com'