我使用此语句来计算特定ID的出现次数
SELECT cms_id, COUNT( * ) AS Number
FROM website
GROUP BY cms_id
ORDER BY `website`.`cms_id` ASC
LIMIT 0 , 30
但是在另一个表中,我有每个cms_id的标题名称
cms_id cms_name
1 wordpress
如何从另一个表中检索名称并显示此名称而不是cms_ID
答案 0 :(得分:2)
SELECT a.cms_id, b.cms_name, COUNT(*) AS Number -- <<== you can remove a.cms_id
FROM website a
INNER JOIN anotherTable b
ON a.cms_id = b.cms_id
GROUP BY a.cms_id, b.cms_name
ORDER BY a.cms_id ASC
LIMIT 0 , 30
要进一步了解联接,请访问以下链接: