我有桌客:
CREATE TABLE clients (
id INT AUTO_INCREMENT NOT NULL,
tariff VARCHAR(255) NOT NULL NULL,
validity VARCHAR(255) NOT NULL,
phoneNumber VARCHAR(255) NOT NULL ,
PRIMARY KEY(id)
) ENGINE=InnoDB CHARACTER SET=UTF8;
INSERT INTO clients (id,tariff,validity,phoneNumber) VALUES (1,"tariff1","10-02-2015","380938474271");
INSERT INTO clients (id,tariff,validity,phoneNumber) VALUES (2,"tariff1","10-02-2016","380938474272");
INSERT INTO clients (id,tariff,validity,phoneNumber) VALUES (3,"tariff2","12-01-2017","380938474273");
INSERT INTO clients (id,tariff,validity,phoneNumber) VALUES (4,"tariff3","10-01-2017","380938474274");
INSERT INTO clients (id,tariff,validity,phoneNumber) VALUES (5,"tariff3","11-02-2017","380938474275");
我的字段有效期是激活日期。
如何从激活日期超过一年的此表字段中进行选择?例如,对于此表,它将使用ID为1和2的客户端。
最佳答案
您应将varchar值转换为正确的日期,并检查是否小于1年
select * from clients
where str_to_date(validity , '%d-%m-%Y') < date_sub(now(), INTERVAL 1 YEAR )
关于mysql - 从激活日期起超过一年的输出数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42339493/