sql喜欢搜索字符

时间:2012-01-10 02:12:29

标签: mysql

你好,我想在5个字符后搜索

(yyyy-mm-dd)
2000-02-01
2001-01-01
2001-01-05
2001-03-03

我想获得mm值

 select * from day , employee 
 where Employee.ID = Day.Employee and employee = "$_ID" 
and day.leaveday like "%$month%";

问题是,如果我使用%%(通配符)所有内容,如20001 - 03 - 03,2000-02-01,它将显示我如何获得价值mm?

有什么想法吗?在此先感谢您的帮助,如果之前有人问过,我真的很抱歉

2 个答案:

答案 0 :(得分:0)

我正在服用它,是一个日期,日期时间或时间戳列。如果不是因为你存储日期而首先制作一个。这也将防止出现诸如20001之类的无效日期。然后使用mysql extract function运行类似这样的东西

 select * from day , employee where Employee.ID = Day.Employee and employee = "$_ID" and extract(month from day.leaveday)=3

答案 1 :(得分:0)

select * from day , employee 
 where Employee.ID = Day.Employee and employee = "$_ID" 
and MONTH(day.leaveday)="$month";