我有這個MySQL選擇查詢:MySQL的 - 篩選記錄其日期是最大的
SELECT s.*
FROM campaign_statistic AS s INNER JOIN campaign AS c ON s.campaign_id = c.campaign_id
WHERE c.campaign_id = 51
AND date(s.created_date) BETWEEN date(c.start_date) AND date(c.end_date)
並得到這樣的結果:
id campaign_id instagram_id media_id has_tag comments_count likes_count created_date status
** *********** ************ **************************** ******** ************* *********** ******************* ******
1 51 1230544324 957801995790641919_1230544324 together 1 16 2015-11-01 13:10:29 1
2 51 1230544324 957799073015065299_1230544324 together 2 11 2015-11-01 13:10:29 1
3 51 1230544324 957790310736521811_1230544324 together 5 20 2015-11-01 13:10:29 1
4 51 1230544324 957801995790641919_1230544324 together 1 16 2015-11-02 13:10:29 1
5 51 1230544324 957799073015065299_1230544324 together 2 11 2015-11-02 13:10:29 1
6 51 1230544324 957790310736521811_1230544324 together 5 20 2015-11-02 13:10:29 1
7 51 1230544324 957801995790641919_1230544324 together 1 16 2015-11-03 13:10:29 1
8 51 1230544324 957799073015065299_1230544324 together 2 11 2015-11-03 13:10:29 1
9 51 1230544324 957790310736521811_1230544324 together 5 20 2015-11-03 13:10:29 1
但我試圖讓只有那些記錄其created_date
是最大從以上結果和最大created_date
是2015-11-03
。
我需要這樣的結果:
id campaign_id instagram_id media_id has_tag comments_count likes_count created_date status
** *********** ************ **************************** ******** ************* *********** ******************* ******
7 51 1230544324 957801995790641919_1230544324 together 1 16 2015-11-03 13:10:29 1
8 51 1230544324 957799073015065299_1230544324 together 2 11 2015-11-03 13:10:29 1
9 51 1230544324 957790310736521811_1230544324 together 5 20 2015-11-03 13:10:29 1
任何想法或建議?
謝謝。
嗨。我試過你的查詢但得到0結果。 –
也許會拋出一個模糊的骨頭給他一個sqlfiddle – Drew
@PHPBaby,在子查詢中缺少內部連接,請再試一次 – FuzzyTree