PHP 访问 SQL 关于四舍五入值的帮助
PHP Access SQL help on round up values
请帮助我 sql 查询从 Access 数据库获取后的值。我正在使用 php 和访问生成标记-sheet。但不能对单个查询的值进行舍入。我正在尝试添加值,但这应该在添加之前先进行汇总。我的意思是如果标记字段包含 14.5 那么在添加但不转换实际数据库值之前应该是 15。这是我的代码...
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 没有 CEILING 函数,如果无法访问 VBA 函数,您可以使用一些数学运算和 Int 函数。
尝试使用此代码。我已经使用这个逻辑来确定它是否应该四舍五入。它假定标记始终为正:
Int(Marks)+IIf(Marks-Int(Marks)>0,1,0)
此外,我对 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";}}}"
请帮助我 sql 查询从 Access 数据库获取后的值。我正在使用 php 和访问生成标记-sheet。但不能对单个查询的值进行舍入。我正在尝试添加值,但这应该在添加之前先进行汇总。我的意思是如果标记字段包含 14.5 那么在添加但不转换实际数据库值之前应该是 15。这是我的代码...
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 没有 CEILING 函数,如果无法访问 VBA 函数,您可以使用一些数学运算和 Int 函数。
尝试使用此代码。我已经使用这个逻辑来确定它是否应该四舍五入。它假定标记始终为正:
Int(Marks)+IIf(Marks-Int(Marks)>0,1,0)
此外,我对 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";}}}"