需要在 mysql 查询函数中使用一些限制和排序代码的解决方案

need solutions with some code of limit and order by in mysql query function

我有table这样的

|post_date |post      |value    |
---------------------------------
|2019-11-05|post      |text     |
|2019-11-05|post      |text     |
|2019-11-05|post      |text     |
|2019-11-05|post      |text     |
|2019-11-06|post      |text     |
|2019-11-06|post      |text     |
|2019-11-07|post      |text     |
|2019-11-08|post      |text     |
|2019-11-08|post      |text     |
|2019-11-08|post      |text     |
|2019-11-08|post      |text     |
|2019-11-08|post      |text     |
|2019-11-08|post      |text     |

我试过这样select

SELECT post_date, count(*) as post FROM myTable GROUP BY post_date ORDER BY post_date ASC LIMIT 3

会这样显示

|post_date |post      |
-----------------------
|2019-11-05|4         |
|2019-11-06|2         |
|2019-11-07|1         |

我需要的就是这个

|post_date |post      |
-----------------------
|2019-11-06|2         |
|2019-11-07|1         |
|2019-11-08|6         |

它看起来像是极限 3 的结果。它将从订单中获取最新的 3 个结果,而不是最旧的

只需将您当前的查询包装在一个子查询中,以强加您想要的日期升序:

SELECT
    post_date,
    post
FROM
(
    SELECT post_date, COUNT(*) AS post
    FROM myTable
    GROUP BY post_date
    ORDER BY post_date DESC
    LIMIT 3
) t
ORDER BY post_date;

Demo