MySQL计数语句

时间:2013-05-07 02:45:02

标签: mysql sql

我使用此语句来计算特定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

1 个答案:

答案 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

要进一步了解联接,请访问以下链接: