我想根据某些条件从表中检索记录
看到这是我的情况:根据月交易类型查询以获取金额总和
见下面是我的表:
+-----------+-------------+
| 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);`
`
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句