gpt4 book ai didi

mysql - 从数据库表中获取每月的记录

转载 作者:行者123 更新时间:2023-11-29 02:24:05 26 4
gpt4 key购买 nike

我想根据某些条件从表中检索记录

看到这是我的条件:查询以根据每月的交易类型获取金额总和

下面是我的表格:

+-----------+-------------+
| Field | Type |
+-----------+-------------+
| tran_id | int(5) |
| cus_name | varchar(30) |
| acc_no | int(10) |
| tran_date | date |
| amount | int(6) |
| tran_type | varchar(20) |
| cus_id | int(5) |
+-----------+-------------+

按照以下格式显示月份值。

+-----------+-------------+
| Month | Month Name |
+-----------+-------------+
| 01 | January |
| 02 | February |
+-----------+-------------+

最佳答案

我认为这就是您所需要的。

select sum(amount) Sum,tran_type,MONTH(tran_date) Month,MONTHNAME(tran_date) Month Name from your_table group by tran_type,MONTH(tran_date);`

`

关于mysql - 从数据库表中获取每月的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26448204/

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