私はこのようなものを持っています:
ID | post_author | post_date | ... | post_title | post_status | ... | post_type
-------------------------------------------------------------------------------
1 | 1 | 2007-08-11| ... | A | publish | ... | post
2 | 3 | 2007-08-12| ... | B | publish | ... | post
3 | 1 | 2007-08-12| ... | C | publish | ... | post
4 | 1 | 2007-08-13| ... | D | publish | ... | post
5 | 3 | 2007-08-13| ... | E | publish | ... | post
私がやりたいことは、ユーザーごとの投稿の量と、最後の投稿のタイトルと ID を取得することです。上記のデータに基づくと、結果は次のようになります。
AuthorID | TotalPosts | PostID | PostTitle
------------------------------------------
1 | 3 | 5 | E
3 | 2 | 4 | D
私が試したのはこれです:
SELECT
p1.post_author AS Author,
count(p1.post_author) AS Posts,
p2.post_title AS Title
FROM
wp_posts AS p1
LEFT JOIN
wp_posts As p2
ON
p1.ID = p2.ID
WHERE
p1.post_type = 'post'
AND
p1.post_status = 'publish'
GROUP BY
p1.post_author
ORDER BY
Posts DESC,
p2.post_date ASC
LIMIT
2
問題は、最後の投稿のタイトルではなく、常に最初の投稿のタイトルを取得することです。最後に挿入された投稿のタイトルを取得する方法はありますか?
敬具