当前位置:Gxlcms > mysql > mysql某列多值查询_MySQL

mysql某列多值查询_MySQL

时间:2021-07-01 10:21:17 帮助过:68人阅读

要求:查询文章内容既包含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');


效果估计很差,请大牛指点点

人气教程排行