gpt4 book ai didi

php - MySQL ORDER BY 问题

转载 作者:行者123 更新时间:2023-11-29 18:02:16 28 4
gpt4 key购买 nike

我可能试图在一个 SQL 语句中做太多事情。我想在输出表中的适当位置获得小计和总计。这是我的 SQL;

SELECT Date, DOW, Week, Year, logdate, Month, monum, netID, Logins, 
creds, newb, netCnt, TOD, netCnt, activity
FROM (SELECT logdate
,activity
,DATE( logdate ) AS Date
,DAYOFWEEK( logdate ) AS DOW
,WEEK( logdate,0 ) AS Week
,YEAR( logdate ) AS Year
,DATE_FORMAT( logdate, '%M' ) AS Month
,DATE_FORMAT( logdate, '%m' ) AS monum
,CONVERT( netID,UNSIGNED INTEGER ) AS netID
,COUNT( callsign ) AS Logins
,COUNT( IF(creds <> '',1,NULL) ) AS creds
,COUNT( IF(comments LIKE '%first log in%',1,NULL) ) AS newb
,count( DISTINCT netID ) AS netCnt
,SUM( DISTINCT netID) AS allCnt
,SEC_TO_TIME( SUM(timeonduty) ) AS TOD
FROM NetLog
WHERE netID <> 0
AND activity NOT LIKE '%TEST%'
AND netcall LIKE '%W0KCN%'
AND substr(logdate,1,4) = 2017
GROUP BY Month, netID WITH ROLLUP ) AS t
ORDER BY t.logdate , logins

(缩写)输出如下所示; Output of Query

您会注意到,直到十月为止,每个月的顺序都是正确的。总计在 10 月之前而非年底(12 月之后)排序。这是我可以在 SQL 中控制的东西还是应该在 PHP 中修复它?我该如何在 SQL 中修复它?

最佳答案

您的第二个字段logins将仅在第一个排序列的相同值内进行相应排序。否则,按第一列优先排序。尝试交换 logdatelogins 并看看会发生什么。

关于php - MySQL ORDER BY 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48233444/

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