gpt4 book ai didi

php - MYSQL 返回日期乱序

转载 作者:行者123 更新时间:2023-12-01 00:25:51 25 4
gpt4 key购买 nike

我按月份和年份列出所有新闻文章,以及该月发生的文章数量...

但是我注意到在新的一年里它只按月排序而不是

这是我的 SQL

$archive1_sql = "SELECT YEAR(`ndate`) AS 'year', MONTH(`ndate`) AS 'month', COUNT(`nid`) AS 'count'  FROM `weaponsnews` GROUP BY YEAR(`ndate`), MONTH(`ndate`) DESC";

它返回

December 2012 (1)
November 2012 (11)
October 2012 (6)
September 2012 (8)
August 2012 (16)
July 2012 (8)
June 2012 (6)
May 2012 (12)
April 2012 (4)
March 2012 (2)
February 2012 (4)
January 2013 (1)

我想要它做的是这样的

January 2013 (1)
December 2012 (1)
November 2012 (11)
October 2012 (6)
September 2012 (8)
August 2012 (16)
July 2012 (8)
June 2012 (6)
May 2012 (12)
April 2012 (4)
March 2012 (2)
February 2012 (4)

我该怎么做?

最佳答案

也添加带有 YEAR 的 DESC

SELECT
YEAR(`ndate`) AS 'year',
MONTH(`ndate`) AS 'month',
COUNT(`nid`) AS 'count'
FROM `weaponsnews`
GROUP BY YEAR(`ndate`) , MONTH(`ndate`)
ORDER BY YEAR(`ndate`) DESC , MONTH(`ndate`) DESC

关于php - MYSQL 返回日期乱序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14528770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com