Home >Database >Mysql Tutorial >mysql某列多值查询_MySQL

mysql某列多值查询_MySQL

WBOY
WBOYOriginal
2016-06-01 13:11:311133browse

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


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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn