查询数值 类型然后返回字符串

String sql = "select t.tpid,eg.egid,DATE_FORMAT(eg.exb_time,'%Y-%m-%d %H:%i') as EXB_TIME,t.papername,t.viewpaper," +
     
   "if(MINUTE(SEC_TO_TIME(eg.testtime))<>0,CONCAT(CONVERT(MINUTE(SEC_TO_TIME(eg.testtime)),char),'分',"+
  
   convert(SECOND(SEC_TO_TIME(eg.testtime)),char),'秒'),CONCAT(CONVERT(SECOND(SEC_TO_TIME(eg.testtime)),char),'秒') ) as TESTTIME ,"+
          
     "case eg.isoffline when 1 then '离线考试' else '在线考试' end isoffline, "+
    
     "case t.viewscore when 0 then '保密' else CONVERT(cast(eg.ExScore as decimal(18,1)),char) end as ExScore,exstate "+

     " from tbexamineegrade eg " +
     " inner join tbtestpaper t on eg.tpid = t.tpid " +
     " inner join tbPaperClass pc on pc.pcid=t.pcid" +
     " where eg.exstate in (4,5)" ;
    
     if(!"".equals(strWhere)){
  sql+=strWhere;
     }
    
    sql += " order by eg.exb_time desc";


mysql> desc tbexamineegrade;
+------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra         
+------------+--------------+------+-----+---------+----------------+
| EGID        | int(10)      | NO   | PRI | NULL    | auto_increment |
| USERID    | int(10)      | YES  |          NULL                   
| TPID         | int(10)      | YES  |        | NULL                   
| WLGID     | int(10)      | YES  |         | NULL                 
| EXTIMES   | int(10)      | NO   |        | NULL                  
| EXSTATE   | int(10)      | YES  |        | NULL                   
| EXB_TIME   | datetime | YES  |        | NULL                   
| EXE_TIME   | datetime | YES  |        | NULL                   
| TESTTIME   | int(100)   | YES  |        | NULL                   
| OBJECTIVE  | double    | YES  |        | NULL                  
| SUBJECTIVE | double   | YES  |        | NULL                  
| EXSCORE    | double    | YES  |        | NULL                  
| PFUSERID   | int(10)     | YES  |        | NULL                  
| EXREMARK   | varchar(255) | YES     |NULL                  
| SERIALNO   | int(10)      | YES  |       | NULL                 
| ISOFFLINE  | int(65)      | YES  |        | NULL                   
| EXPORTDATE | datetime     | YES     | NULL                 
+------------+--------------+------+-----+---------+----------------+
17 rows in set

CONCAT(CONVERT(MINUTE(SEC_TO_TIME(eg.testtime)),char),'分');

注意查找的是testtime 字段 是int类型 所以 要返回给页面一个字符串 所以 用convert转换

类似的查询还有
case t.viewscore when 0 then '保密' else CONVERT(cast(eg.ExScore as decimal(18,1)),char) end as ExScore

 

你看 要查询的字段都是int 或者double类型 也就是数值 而我要返回字符串 所以要用convert 转换

你可能感兴趣的:(字符串)