-1

我是 MySQL 语法的新手,请帮忙。

更新查询:

$query = mysql_query("SELECT  campaign, team, employeeName, shiftcode, scheduleDate,STR_TO_DATE(scheduleIn,'%h:%i %p')  as ScheduleIn, STR_TO_DATE(scheduleOut,'%h:%i %p')  as ScheduleOut, STR_TO_DATE(MID(scheduleIn,7,4), '%h:%i') as sIn FROM tbl_uploadedschedule WHERE NOT EXISTS(SELECT scOrigtimein, scOrigtimeout FROM tbl_shiftcode WHERE STR_TO_DATE(tbl_uploadedschedule.scheduleIn,'%h:%i %p') = tbl_shiftcode.scOrigtimein or STR_TO_DATE(tbl_uploadedschedule.scheduleOut,'%h:%i %p')=tbl_shiftcode.scOrigtimeOut )") or die(mysql_error());

但它什么也不返回,不知道 STR_TO_DATE() 是否在 WHERE 子句中不能正常工作

4

1 回答 1

0

尝试使用NOT EXISTS类似:

SELECT * FROM TableB
WHERE NOT EXISTS 
(SELECT * FROM TableA
 WHERE TableB.Shift_Codes=TableA.Shift_Codes
 AND TableB.Time_in = TableA.Time_in 
 AND TableB.Time_out = TableA.Time_out)

小提琴演示

使用STR_TO_DATE()

SELECT * FROM TableB
WHERE NOT EXISTS 
(SELECT * FROM TableA
 WHERE TableB.Shift_Codes=TableA.Shift_Codes
 AND STR_TO_DATE(TableB.Time_in,'%h:%i:%s') = STR_TO_DATE(TableA.Time_in,'%h:%i:%s') 
 AND STR_TO_DATE(TableB.Time_out,'%h:%i:%s') = STR_TO_DATE(TableA.Time_out,'%h:%i:%s'))

演示

于 2013-11-15T02:27:03.770 回答