mysql某列多值查询_MySQL
程序员文章站
2022-05-20 08:55:48
...
要求:查询文章内容既包含aa且包含cc的所有文章的文章标题
查询SQL:SELECT kk.`title`,COUNT(1) times FROM (SELECT `title`, `content` FROM `article` WHERE `content` IN ('aa', 'cc') GROUP BY `title`, `content`) kk GROUP BY kk.`title` HAVING times>=2;CREATE TABLE IF NOT EXISTS `article` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(100) NOT NULL, `content` varchar(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;INSERT INTO `article` (`id`, `title`, `content`) VALUES(1, 'a', 'aa'),(2, 'a', 'cc'),(3, 'a', 'aa'),(4, 'c', 'cc');
效果估计很差,请大牛指点点