【发布时间】:2025-12-29 19:40:15
【问题描述】:
您好,我在 mysql 中有一个表,当另一列中有重复数据时,我想从该表中汇总多条记录。 例如 我有这个数据表:
table name = register_user_course
columns = register_user_course_id, register_user_register_id, register_user_course_name, register_user_course_price
data like =
1 | 3 | 3dmax | 300
2 | 3 | photoshop | 500
4 | 4 | 3dmax | 300
5 | 6 | icdl | 500
6 | 4 | icdl | 900
7 | 9 | accounting | 1000
我想创建这样的输出代码
1 | 3 | 800 // sum all register_course_price with the same register_user_register_name on aoutput one records
4 | 4 | 1200 // sum all register_course_price with the same register_user_register_name on aoutput one records
5 | 6 | 500
7 | 9 | 1000
让我有另一个这样的表
table name = deposit
columns = deposit_id, deposit_abutment_id, deposit_price
table data like=
1 | 13 | 0,10,50,0,0 // every comma sign has one way to get money
2 | 13 | 10,30,0,0,0
3 | 13 | 100,0,0,0,0
4 | 15 | 50,0,0,0,50
5 | 17 | 100,10,5,0,0
6 | 15 | 33,50,0,0,0
我也想这样展示
1 | 13 | 200 // sum all way and all deposit that one abutment_user_id
4 | 15 | 183
5 | 17 | 115
【问题讨论】:
-
你试过
group by和sum吗?
标签: php mysql sql group-by sum