[英]PHP Access SQL help on round up values
Please help me on sql queries for round up the value after fetching from Access database. 从Access数据库中获取值后,请帮助我进行sql查询以求取整值。 I'm working on generating mark-sheet using php and access.
我正在使用php和access生成标记表。 But can't round up the values on a single query.
但是不能在单个查询中将值四舍五入。 I'm trying to add values but this supposed to be round up first before the addition.
我正在尝试添加值,但这应该在添加之前先进行四舍五入。 I mean if marks field contain 14.5 then should be 15 before adding but not converting the actual database value.
我的意思是,如果标记字段包含14.5,则在添加但不转换实际数据库值之前应为15。 Here is my code...
这是我的代码...
if(isset($_GET['action']) && $_GET['action']=='rlist'){
if($_GET['element_1']=="IX"){
if( $_GET['element_2']!=1){
$sql="select m.StudentId,StudentName, m.Roll,m.Sec,m.P1,m.P2,m.P3,m.S1,m.S2,m.S3,m.Total from StudentMain right join(select StudentId, Roll, Sec,Sum(iif(ExamType=4,Marks,0)) as P1,Sum(iif(ExamType=5,Marks,0)) as P2,Sum(iif(ExamType=6,Marks,0)) as P3, Sum(iif(ExamType=1,Marks,0)) as S1,Sum(iif(ExamType=2,Marks,0)) as S2,Sum(iif(ExamType=3,Marks,0)) as S3, (S1+S2+S3+P1+P2+P3) as Total from Marks where Class='".$_GET['element_1']."' and Sec='".$_GET['element_2']."'group by StudentId,Roll,Sec) as m on StudentMain.StudentId=m.StudentId order by m.Roll";}}}
$rs = odbc_exec($conn,$sql)or die (print odbc_errormsg());'
Access doesn't have a CEILING function, and without having access to a VBA function, you could use some maths and the Int function. Access没有CEILING函数,并且没有访问VBA函数的权限,您可以使用一些数学运算和Int函数。
Try using this code. 尝试使用此代码。 I've used this logic to determine if it should round up or not.
我已经使用此逻辑来确定是否应四舍五入。 It assumes that marks is always positive:
它假定标记始终为正:
Int(Marks)+IIf(Marks-Int(Marks)>0,1,0)
Also, I've formatted the SQL code to make it easier to read and maintain. 另外,我对SQL代码进行了格式化,以使其更易于阅读和维护。
$sql="select m.StudentId,StudentName, m.Roll,m.Sec,m.P1,m.P2,m.P3,m.S1,m.S2,m.S3,m.Total " .
"from StudentMain " .
"right join( " .
"select StudentId, Roll, Sec,Sum(iif(ExamType=4,Marks,0)) as P1, " .
"Sum(iif(ExamType=5,Int(Marks)+IIf(Marks-Int(Marks)>0,1,0),0)) as P2, " .
"Sum(iif(ExamType=6,Int(Marks)+IIf(Marks-Int(Marks)>0,1,0),0)) as P3, " .
"Sum(iif(ExamType=1,Int(Marks)+IIf(Marks-Int(Marks)>0,1,0),0)) as S1, " .
"Sum(iif(ExamType=2,Int(Marks)+IIf(Marks-Int(Marks)>0,1,0),0)) as S2, " .
"Sum(iif(ExamType=3,Int(Marks)+IIf(Marks-Int(Marks)>0,1,0),0)) as S3, " .
"(S1+S2+S3+P1+P2+P3) as Total " .
"from Marks w " .
"here Class='".$_GET['element_1']."' " .
"and Sec='".$_GET['element_2']."' " .
"group by StudentId,Roll,Sec) as m " .
"on StudentMain.StudentId=m.StudentId order by m.Roll";}}}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.