mysql动态生成where子句

时间:2015-07-08 18:39:54

标签: mysql

在select语句中使用OR时的正确用法是什么? 我有3列我想用来过滤搜索结果:  EmployeeDepartmentDate_Hired

查询是一个简单的选择

SELECT Col1, Col2, Col3,.... FROM table Where
Employee = "" OR
Department = "" OR
Date_Hired BETWEEN "" AND ""

我尝试做的是用户是否只想使用过滤结果 3列中的任何一列,例如,如果它像:

WHERE Employee = "Mickey"
OR Department = "" 
OR Date_Hired BETWEEN "" AND ""

或者,如果用户还想搜索所雇用的日期

WHERE Employee = "Mickey"
OR Department = "" 
OR Date_Hired BETWEEN "2014-01-01" AND "2014-01-31"

使用它的正确方法是什么?

0 个答案:

没有答案