gpt4 book ai didi

php - 按月份分组并按时间顺序而不是按字母顺序在 mysql 中显示

转载 作者:行者123 更新时间:2023-11-30 00:58:34 24 4
gpt4 key购买 nike

虽然查询返回结果,但按月份分组按字母顺序返回结果,如 April、August、June ...,但它应该按时间顺序返回结果,如 Jan、Feb、....

SELECT Concat(Monthname(a.fdate), '-', Year(a.fdate)) AS Month, 
s.new_state AS State,
d.new_dist AS District,
b.ifbook AS Book,
Sum(a.amt) AS Amount
FROM str a
JOIN sc b
ON b.scd = a.isc
JOIN USER c
ON a.ed = c.str
JOIN state_mapping s
ON b.state = s.org_state
JOIN dist_mapping d
ON b.dist = d.org_dist
WHERE Trim(b.ifbook) <> ''
AND b.ifbook IS NOT NULL
AND b.ifbook NOT LIKE '%TR%'
AND Trim(d.new_dist) <> ''
AND d.new_dist IS NOT NULL
GROUP BY b.ifbank,
d.new_dist,
s.new_state,
month

如何修改查询以实现相同的效果?

最佳答案

在不了解您的模型的情况下,我可以建议您尝试一下:

select
concat(monthname(a.fdate),'-',year(a.fdate)) Month,
s.new_state State,
d.new_dist District,
b.ifbook Book,
sum(a.amt) Amount
from str a
JOIN sc b on b.scd = a.isc
JOIN user c on a.ed = c.str
JOIN state_mapping s on b.state = s.org_state
JOIN dist_mapping d on b.dist = d.org_dist
where TRIM(b.ifbook) <> '' and b.ifbook IS NOT NULL and b.ifbook not like '%TR%'
and TRIM(d.new_dist) <> '' and d.new_dist IS NOT NULL
group by b.ifbank, d.new_dist, s.new_state, Month
order by year(a.fdate), month(a.fdate)

关于php - 按月份分组并按时间顺序而不是按字母顺序在 mysql 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20343729/

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