douba4275 2019-08-12 18:44
浏览 62

如何使用不同的id对列进行求和,但具有groupby id

I have a table bills which has several columns including bus_billed_amount,uniform_billed_amount, registration_number and auto_incremented id

Now I grouped, using an id, depending on the required feature to give uniforms to the students. Let's say, a student has been billed for uniform this semester and next semester as well meaning they have to be treated separately in order to separate each billing despite the student has the same registration number

Now, my question is, how can I find total of the two billings yet bearing the fact that each billing of the student has to be shown???

$res = mysqli_query($con,"SELECT *, IF(status=1,'Active','Inactive') As status,
IF((SUM(r.uniform_billed) - (SELECT SUM(s.uniform_paid) FROM bill_payments  AS s WHERE r.registration_number = s.registration_number AND r.status ='1'))> 0,'Payment Not Done','Paid') AS pay_status,
( SUM( r.uniform_billed ) - ( SELECT SUM(s.uniform_paid) FROM bill_payments  AS s WHERE r.registration_number = s.registration_number AND r.status ='1' ) ) AS uniform_balance,
If(uniform_state='1','Uniform Given', 'Uniform Not Given') as given_state
FROM bills as r 
WHERE r.uniform_state='0' AND r.status='1' 
GROUP BY id 
ORDER BY firstname ASC 
LIMIT ".$per_page." OFFSET ".$offset);

mysqli_close($con);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题