我有一张 table ,它看起来像,
| user_id | url | is_bookmark | is_history <== schema
示例数据:
[2, "http://www.stackoverflow.com", 1 ,0]
[3, "http://www.stackoverflow.com", 1 ,0]
[4, "http://www.stackoverflow.com", 1 ,1]
[5, "http://www.php.net", 1 ,0]
并且需要下表,
| url | total_bookmark | total_history <== schema
此表的样本数据
["http://www.stackoverflow.com", 3 , 1]
["http://www.php.net", 1 , 0]
我使用 2 个查询来执行此操作,但可以在 1 个查询中完成吗?
最佳答案
试试这个:
select url , count(*) total_bookmark, sum(is_history) total_history
from yourtable
group by url
关于mysql - 计算mysql列中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721005/