如何从文本框中取出参数作为日期的一种形式

时间:2017-03-08 12:19:01

标签: java mysql jsp

我也有一个疑问如何在mysql中使用like和operator之间。 我想从表单中获取两个参数,这个特定的日期在like operator

中使用

我的完整代码是:

 String sql = "SELECT city_name"
        + ",Assignedto"
        + ",COUNT(Assignedto) as TC"
        + ",CONCAT(Round(count(case when STATUS = 'CLOSED' then 1 else null end) * 100 / count(1)),'%') as SC"
        + ",CONCAT(Round(count(case when STATUS = 'PENDING' then 1 else null end) * 100 / count(1), '%'),'%') as PC"
        + ",Round(SUM(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE))/480) as WH "
        + ",ROUND((126720-sum(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE)))/480) as VH"
        + ", CONCAT(ROUND(COUNT(Feedback_Rate)/COUNT(Assignedto)*100,'%'),'%') as Feed_Percent"
        + ", Round(SUM(Feedback_Rate)/(count(Feedback_Rate)*5)*5,1) as AVG_Feedback "
        +", Round(COUNT(CASE WHEN TIMESTAMPDIFF(MINUTE,request_date,REPLY_dATE) <= MINUTE(etr)"
        +" THEN 1 ELSE NULL END)*100/count(1)) AS etr"
        + " FROM `it_service_ticket` "
        + "INNER JOIN `it_problem`ON "
        + "`it_service_ticket`.`it_problem_id`=`it_problem`.`it_problem_id` "
        + "INNER JOIN `city_master` ON "
        + "`it_service_ticket`.cityid=`city_master`.city_id "
        + "WHERE "
        + "`it_service_ticket`.`REPLY_dATE` LIKE BETWEEN ? AND ? "

        + "GROUP BY Assignedto order by city_name desc";

PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, request.getParameter("keyword"));
//pst.setString(2, request.getParameter("keyword1"));
ResultSet rs = pst.executeQuery();
while (rs.next()) {
    //.....
}

1 个答案:

答案 0 :(得分:0)

  

如何在sql查询中使用between和like运算符

这里使用的是语法:

SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;

这里使用的是语法:

expression BETWEEN value1 AND value2;

你不能像喜欢的那样在喜欢和喜欢之间混音。

相反,您可以使用:

`it_service_ticket`.`REPLY_dATE` BETWEEN ? AND ? 

并且您必须为两个日期设置Parametre而不仅仅是一个:

pst.setString(1, request.getParameter("date1"));
pst.setString(2, request.getParameter("date2"));

如果你想同时使用它们,那么可以像这样使用 AND

expression LIKE ? AND `it_service_ticket`.`REPLY_dATE` BETWEEN ? AND ?

pst.setString(1, "param1");
pst.setString(2, "param2");
pst.setString(1, "param3");