MySQL删除日期和时间比较

时间:2017-08-16 12:55:46

标签: mysql

CREATE TABLE `appointments` (
`id` int(11) NOT NULL,
`app_date` date NOT NULL,
`mobile` varchar(16) NOT NULL,
`time` time NOT NULL,
`duration` int(3) NOT NULL,
`services` varchar(256) NOT NULL,
`status` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `appointments` (`id`, `app_date`, `mobile`, `time`, `duration`, 
`services`, `status`) VALUES
(11, '2017-09-28', '991694', '11:00:00', 1, 'PP', 'Booked'),
(12, '2017-09-28', '991694', '12:00:00', 1, 'FT', 'Booked'),
(13, '2017-09-29', '991694', '10:00:00', 1, 'HC;FT', 'Booked'),
(14, '2017-09-11', '991694', '11:00:00', 1, 'T;W;HS;PP', 'Booked');

 DELETE from appointments where 'mobile' = '991694' and 'app_date' = 
 '2017-09-28' and 'time' = '11:00:00'

没有删除任何行?返回0行受影响。请在这里建议出现问题。

我也尝试过 从约会中删除' mobile' =' 991694'和' app_date' = date' 2017-09-28'和'时间' =时间' 00:00:00'

1 个答案:

答案 0 :(得分:3)

删除列名前的引号。您没有检查行上的值,您是比较字符串。请注意,在mysql中

' != `

这应该有效:

DELETE from appointments where mobile = 991694 and app_date = '2017-09-28' and time = '11:00:00'