ÎÒÓõÄÊÇmysql5.0£¬
ÎÒ³ÌÐòÖÐÓõ½ÁËÒ»¾äsqlÊÇ
SQL code
select count(DISTINCT id) from Policyinfo p where p.filename not in
(select p2.filename from Policyreadinfo p2 where p2.reader='test')
µ«ÊÇÿ´ÎÔÚ³ÌÐòÖÐÿ´ÎÖ´ÐÐÕâ¾äsqlʱÍøÒ³¾ÍÌØÂý£¬Òª10¶àÃ룬¶øÕâ2¸ö±íµÄ¼Ç¼ÐÐÊýÒ²¾Í1000¶à¶øÒÑ£¬ÎÒ°ÑÕâ¾äsqlµ¥¶ÀÄõ½SQLyog EnterpriseÀïÖ´ÐÐÒ²ºÜÂý£¬ºÍÍøÒ³µÄÖ´ÐÐʱ¼ä²î²»¶à¡£ÎÒÏëÔÚpolicyreadinfo±íÀィ¸öË÷Òý£¬µ«ÊÇÿ´ÎÎÒÖ´Ðн¨Á¢Ë÷ÒýµÄsqlʱ£¬MYSQL¾Í»áÍ£µô£¬½¨²»ÁËË÷Òý¡£
ÎÒÓõĵ½µÄ½á¹ûÈçÏ£º
"id", "select_type", "table","type","possible_keys","key","key_len","ref","rows","Extra"
"1", "PRIMARY", "p", "ALL", \N, \N, \N, \N, "1715","Using where"
"2", "DEPENDENT SUBQUERY","p2", "ALL", \N, \N, \N, \N, "4196","Using where"
ÆäÖбíPolicyinfo½á¹¹Îª
SQL code
CREATE TABLE `policyinfo` (
`id` int(11) NOT NULL auto_increment,
`filenum` varchar(50) default NULL,
`filename` varchar(100) default NULL,
`filecontent` longtext,
`writetime` datetime default NULL,
`writer` varchar(100) default NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Policyreadinfo ±íµÄ½á¹¹ÊÇ
SQL code
CREATE TABLE `policyreadinfo` (
`id` int(11) NOT NULL auto_increment,
`filename` varchar(500) default NULL,
`reader` varchar(100) default NULL,
`readtime` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ÕâÊÇÎÒÔÚÂÛ̳ÉÏÌá³öµÄÎÊÌâ¡£Ô´ÎÄÁ´½Ó£ºhttp://topic.csdn.net/u/20100325/10/801d54f6-121b-4431-873d-e061dc60c6a6.html
ºóÀ´¾¹ýÎҵIJâÊÔ£¬ÖÕÓÚÔçµ½½â¾ö°ì·¨À²¡£ÔÚ2¸ö±ífilenameÉÏ·Ö±ð½¨Á¢Ë÷Òý¡£Ö®Ç°Ò²ÓÐÏë¹ýÕâ¸ö°ì·¨£¬µ«ÊDz»ÖªµÀΪʲôһִÐн¨Á¢Ë÷ÒýµÄSQL£¬MYSQL¾Í»áËÀµô¡£ËùÒÔºóÀ´¾ÍûÓг¢ÊÔÕâÖÖ·½·¨À²¡£
ºóÀ´ÔÚ±¾»ú²âÊÔ·¢ÏÖ½¨Á¢Ë÷ÒýºóµÄ²éѯËÙ¶ÈÊǽ¨Á¢Ç°µÄN±¶¡£
ÓÚÊǾÍÐÞ¸ÄpolicyreadinfoÔÚËûÕâÀï¼ÓÒ»¸öpolicyinfo_id µÄ×ֶα£´æpolicyinfoµÄid×ֶΡ£È»ºóÔÙÔÚpolicyinfo_idÉϽ¨Á¢Ë÷Òý¡£ÎÊÌâÖÕÓÚ½â¾öÁË¡£ºÇºÇ
×ܵÄÓÅ»¯SQLÓï¾äÊÇ
-- Ôö¼ÓId ×Ö¶Î
ALTER TABLE policyreadinfo ADD `policyinfo_id` int(11);
-- ¸üÐÂpolicyreadinfo ±í£¬ÓÐЩ×Ö¶ÎΪnullÊÇÒòΪËû°ÑÕþ²ßÃû×Ö¸ÄÁË
update policy