我想獲取X最後的條目,如果可能的話在一個查詢來獲取:SQL從「自定義」 post_type計數的用戶自定義post_type的個體數量
- 最後4個不同的用戶
- 排除
'ID' = '1'
WITH post_type
- =
'custom'
- 通過
date
或ID
(DESC
) - 計數 '自定義' PO的總數目有序st_type爲每個用戶(COUNT())
這裏是一個數據例如:
Table Name: 'post'
ID | user | Date | title | status | post_type
| | | | |
"2785" | "1" | "2016-05-24 18:49:15" | "Title" | "published" | "page_post"
"2783" | "5" | "2016-05-24 11:24:08" | "Title" | "published" | "custom"
"2781" | "1" | "2016-05-18 20:40:11" | "Title" | "published" | "custom"
"2759" | "3" | "2016-05-07 14:00:22" | "Title" | "published" | "custom"
"2757" | "12" | "2016-05-02 12:41:00" | "Title" | "published" | "custom"
"2756" | "1" | "2016-04-30 22:47:07" | "Title" | "published" | "custom"
"2755" | "5" | "2016-04-29 13:54:21" | "Title" | "published" | "blog_post"
"2754" | "1" | "2016-04-29 11:33:36" | "Title" | "published" | "page_post"
"2738" | "3" | "2016-05-06 12:45:58" | "Title" | "published" | "custom"
"2736" | "12" | "2016-04-24 17:17:04" | "Title" | "published" | "custom"
"2683" | "15" | "2016-04-22 20:27:45" | "Title" | "published" | "custom"
"2681" | "18" | "2016-04-21 00:20:55" | "Title" | "published" | "custom"
"2671" | "1" | "2016-04-11 18:38:57" | "Title" | "published" | "other_post"
"2652" | "4" | "2016-04-02 17:43:41" | "Title" | "published" | "custom"
"2651" | "5" | "2016-03-28 17:12:00" | "Title" | "published" | "custom"
"2639" | "18" | "2016-03-22 14:58:00" | "Title" | "published" | "custom"
"2630" | "19" | "2016-03-21 15:27:00" | "Title" | "published" | "custom"
"2617" | "14" | "2016-03-17 12:22:06" | "Title" | "published" | "custom"
"2616" | "5" | "2016-03-16 15:23:00" | "Title" | "published" | "page_post"
"2598" | "4" | "2016-03-14 15:27:29" | "Title" | "published" | "custom"
"2596" | "2" | "2016-03-10 17:43:00" | "Title" | "published" | "custom"
"2571" | "1" | "2016-03-09 14:19:31" | "Title" | "published" | "blog_post"
"2250" | "19" | "2016-02-29 12:15:48" | "Title" | "published" | "custom"
"2249" | "15" | "2016-02-29 09:45:35" | "Title" | "published" | "custom"
"2215" | "13" | "2016-02-22 18:21:54" | "Title" | "published" | "custom"
"2201" | "3" | "2016-02-15 17:40:00" | "Title" | "published" | "custom"
"1914" | "2" | "2015-11-13 12:08:00" | "Title" | "published" | "other_post"
,我有不完整的查詢:
SELECT *
FROM 'posts'
WHERE 'user' != 1 AND 'post_type' = 'custom_type'
GROUP BY 'user'
ORDER BY 'ID' DESC LIMIT 4
排序方式ID
是這裏類似比通過date
訂購。 沒有GROUP BY 'user'
這個工作,但問題是,我想避免在這個選擇2個'自定義'發佈一個用戶:我需要選擇4個不同的用戶。 所以我的問題是GROUP BY
。
我該如何解決這個問題?
最後一件事:
是否有可能與COUNT()
,本次評選共統計「自定義」的帖子爲每個用戶,並在新列返回值?
鑑於這4用戶應通過查詢中選擇的OP的採樣數據? –
你能告訴我們查詢應該返回哪4個用戶標識(使用帖子中提供的樣本數據)嗎? –
@GiorgosBetsos這更清楚:)當然是。這裏是身份證號碼:2783,2759,2757,2683 – LoicTheAztec