带数学计算的MySQL

时间:2017-08-24 16:58:38

标签: mysql database math

我为图书馆管理系统创建了数据库。 查询将返回以下问题!!!

  • 在过去6个月内针对特定部门的每位学生找到应付罚款(罚款)
  • 假设:罚款金额为2 /天(以分或INR计),第二天会加倍,同样为2,4,8,16,32,64,128,256 .......

我的问题代码是:

SELECT 
GROUP_CONCAT(s.id) AS IDs,
GROUP_CONCAT(DATEDIFF(returned,exp_date)) AS DAYS,
GROUP_CONCAT(POW(2,DATEDIFF(returned,exp_date))) AS FINE_PER_HEAD,
SUM(POW(2,DATEDIFF(returned,exp_date))) AS Fine,s.dept
FROM student s
INNER JOIN borrower b
ON s.id=b.id
WHERE returned>exp_date AND exp_date 
BETWEEN DATE_SUB(NOW(), INTERVAL 6 MONTH) AND NOW() 
GROUP BY s.dept;`

在输出中,我在精确列Here,The Image contains the output screen of the result that i got from the query

中得到了2 ^ 33分(33天)
IDs               DAYS        FINE_PER_HEAD          Fine       dept
----------------------------------------------------------------------------    
1,36,138          2,5         4,32                   36         CS  
116,104,109,112   1,11,8,33   2,2048,256,8589934592  8589936898 Electronics 
196               13          8192                   8192       Maths   
1,73,174          10,14       1024,16384             17408      Mechanical  
1,48,150          6,5         64,32                  96         Physics 

我如何限制不超过特定金额的罚款金额,例如< 5000或6000分>无论如何,我该怎么办?

0 个答案:

没有答案