我有一个名为“文章”的表。文章(id,文章,类别,标题)。我的表结构如下:
桌子 :
+----+-------------------------+---------------+
| id | article| category | title |
+----+-------------------------+---------------+
| 1 | a1 | a | ta1 |
| 2 | a2 | a | ta2 |
| 3 | b1 | b | tb1 |
| 4 | b2 | b | tb2 |
| 5 | b3 | b | tb3 |
| 6 | c1 | c | tc1 |
| 7 | c2 | c | tc2 |
| 8 | c3 | c | tc3 |
+----+-------------------------+---------------+
一个“类别”可以有多个与之相关的“文章”,即多个文章可以属于同一类别。我必须在每个类别中找到最后输入的文章的完整记录。
SELECT id,article,category,title FROM articles
WHERE article IN(SELECT MAX(article) FROM articles GROUP BY category)
此查询给出:
+----+-------------------------+-------+
| id | article| category | title |
+----+-------------------------+-------+
| 2 | a2 | a | ta2 |
| 5 | b3 | b | tb3 |
| 8 | c3 | c | tc3 |
+----+-------------------------+--------
现在连同这个输出,我必须在每个类别中找到 COUNT 篇文章。我需要的输出是:
+----+-------------------------+-------+-------+
| id | article| category | title | Count |
+----+-------------------------+-------+-------+
| 2 | a2 | a | ta2 | 2 |
| 5 | b3 | b | tb3 | 3 |
| 8 | c3 | c | tc3 | 3 |
+----+-------------------------+----------------+
帮我查询一下?????????/