只需使用COUNT
函数计数from_id
。如果你想在组中计数,请使用GROUP BY
子句。像这个。
SELECT `name`, COUNT(from_id) AS `COUNT`
FROM myTable
GROUP BY `name`;
这将返回您想要的结果。
现在你想把它插入到新表中然后你可以这样做:
INSERT INTO newTable (`name`, `count`)
SELECT `name`, COUNT(from_id) AS `COUNT`
FROM myTable
GROUP BY `name`;