gpt4 book ai didi

mysql - 压缩多个 OR 条件

转载 作者:可可西里 更新时间:2023-11-01 08:23:21 26 4
gpt4 key购买 nike

我必须从表中删除多个 ID,不幸的是,“我”ID 散落在各列中。

有什么方法可以压缩这种类型的查询吗?

DELETE FROM table 
WHERE
I1 = 1 OR I2 = 1 OR I3 = 1 OR I4 = 1 OR I5 = 1 OR
I6 = 1 OR I7 = 1 OR R1 = 1 OR R2 = 1 OR R3 = 1;

表:

DROP TABLE IF EXISTS `recipes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `recipes` (
`ID` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`I1` smallint(5) unsigned NOT NULL,
`I2` smallint(5) unsigned NOT NULL,
`I3` smallint(5) unsigned NOT NULL,
`I4` smallint(5) unsigned NOT NULL,
`I5` smallint(5) unsigned NOT NULL,
`I6` smallint(5) unsigned NOT NULL,
`I7` smallint(5) unsigned NOT NULL,
`I8` smallint(5) unsigned NOT NULL,
`R1` smallint(5) unsigned NOT NULL,
`R2` smallint(5) unsigned NOT NULL,
`R3` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=3500 DEFAULT CHARSET=utf8 AVG_ROW_LENGTH=79;
/*!40101 SET character_set_client = @saved_cs_client */;

最佳答案

当条件值匹配时尝试下面的查询

DELETE FROM table WHERE 1 in (I1,I2,I3,I4,I5,I6,I7,R1,R2,R3);

关于mysql - 压缩多个 OR 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57122488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com