¹ØÓÚSQLÖÐcountµÄЧÂÊ
COUNT(*)ÓëCOUNT(COL)
ÍøÉÏËÑË÷ÁËÏ£¬·¢ÏÖ¸÷ÖÖ˵·¨¶¼ÓУº
±ÈÈçÈÏΪCOUNT(COL)±ÈCOUNT(*)¿ìµÄ£»
ÈÏΪCOUNT(*)±ÈCOUNT(COL)¿ìµÄ£»
»¹ÓÐÅóÓѺܸãЦµÄ˵µ½Õâ¸öÆäʵÊÇ¿´ÈËÆ·µÄ¡£
ÔÚ²»¼ÓWHEREÏÞÖÆÌõ¼þµÄÇé¿öÏ£¬COUNT(*)ÓëCOUNT(COL)»ù±¾¿ÉÒÔÈÏΪÊǵȼ۵ģ»
µ«ÊÇÔÚÓÐWHEREÏÞÖÆÌõ¼þµÄÇé¿öÏ£¬COUNT(*)»á±ÈCOUNT(COL)¿ì·Ç³£¶à£»
¾ßÌåµÄÊý¾Ý²Î¿¼ÈçÏ£º
mysql> SELECT COUNT(*) from cdb_posts where fid = 604;
+————+
| COUNT(fid) |
+————+
| 79000 |
+————+
1 row in set (0.03 sec)
mysql> SELECT COUNT(tid) from cdb_posts where fid = 604;
+————+
| COUNT(tid) |
+————+
| 79000 |
+————+
1 row in set (0.33 sec)
mysql> SELECT COUNT(pid) from cdb_posts where fid = 604;
+————+
| COUNT(pid) |
+————+
| 79000 |
+————+
1 row in set (0.33 sec)
COUNT(*)ͨ³£ÊǶÔÖ÷¼ü½øÐÐË÷ÒýɨÃ裬¶øCOUNT(COL)¾Í²»Ò»¶¨ÁË£¬ÁíÍâÇ°ÕßÊÇͳ¼Æ±íÖеÄËùÓзûºÏµÄ¼Í¼×ÜÊý£¬¶øºóÕßÊǼÆËã±íÖÐËùÓзûºÏµÄCOLµÄ¼Í¼Êý¡£»¹ÓÐÓÐÇø±ðµÄ¡£
COUNTʱµÄWHERE
¼òµ¥ËµÏ£¬¾ÍÊÇCOUNTµÄʱºò£¬Èç¹ûûÓÐWHEREÏÞÖƵĻ°£¬MySQLÖ±½Ó·µ»Ø±£´æÓÐ×ܵÄÐÐÊý
¶øÔÚÓÐWHEREÏÞÖƵÄÇé¿öÏ£¬×ÜÊÇÐèÒª¶ÔMySQL½øÐÐÈ«±í±éÀú¡£
ÓÅ»¯×ܽ᣺
1.ÈκÎÇé¿öÏÂSELECT COUNT(*) from tablenameÊÇ×îÓÅÑ¡Ôñ£»
2.¾¡Á¿¼õÉÙSELECT COUNT(*) from tablename WHERE COL = ‘value’ ÕâÖÖ²éѯ£»
3.¶Å¾øSELECT COUNT(COL) from tablename WHERE COL2 = ‘value’ µÄ³öÏÖ¡£
Ïà¹ØÎĵµ£º
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://www.ibatis.com/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- ÅäÖúÍÓÅ»¯SQL Map½âÎöʵÀýµÄÉ趨 -->
<settings cacheModelsEnabled=" ......
ÎÄÕÂÓÉÀ´£º ×î½üÐèÒª×öÕâÑùµÄ²âÊÔ:Install the products on machine which case-insensitive SQL installed.
Ëùνcase-insensitive SQL installed¡¡Ö¸ÔÚÊý¾Ý¿â°²×°Ê±Ñ¡ÔñÅÅÐò¹æÔòʱ¡¡ÐèҪѡÔñ´óСдÇø±ðµÄ¹æÔò¡£
¡¡¡¡ÅÅÐò¹æÔò¼ò½é£º
¡¡¡¡¡¡¡¡MSÊÇÕâÑùÃèÊöµÄ£º"ÔÚ Micr ......
TOP ÔöÇ¿¹¦ÄÜ
1¡¢TOP ÔöÇ¿¡£¿ÉÒÔÖ¸¶¨Ò»¸öÊý×Ö±í´ïʽ£¬ÒÔ·µ»ØҪͨ¹ý²éѯӰÏìµÄÐÐÊý»ò°Ù·Ö±È£¬»¹¿ÉÒÔ¸ù¾ÝÇé¿öʹÓñäÁ¿»ò×Ó²éѯ¡£
¿ÉÒÔÔÚDELETE¡¢UPDATEºÍINSERT²éѯÖÐʹÓÃTOPÑ¡Ïî¡£
2¡¢¸üºÃµØÌæ»»SET ROWCOUNTÑ¡Ïʹ֮¸üΪÓÐЧ¡£
OUTPUT
1¡¢SQL Server 2005ÒýÈëÒ»¸öеÄOUTPUT×Ӿ䣬ÒÔʹÄú¿ÉÒÔ³åÐÞ¸ÄÓï¾ä(INSERT¡ ......
Êý¾Ý¿âÐÔÄܵ÷ÓÅÊÇÿһ¸öÓÅÐãSQL Server¹ÜÀíÔ±×îÖÕµÄÔðÈΡ£ËäÈ»±£Ö¤Êý¾ÝµÄ°²È«ºÍ¿ÉÓÃÐÔÊÇÎÒÃǵÄ×î¸ßµÄÄ¿±ê£¬µ«ÊǼÙÈçÊý¾Ý¿âÓ¦ÓóÌÐòÎÞ·¨Âú×ãÓû§µÄÒªÇó£¬ÄÇôDBAÃÇ»áÒòΪÐÔÄܵÍϵÄÉè¼ÆºÍʵÏÖ¶øÊܵ½Ö¸Ôð¡£SQL Server 2005ÔÚÊý¾Ý¿âÐÔÄÜ·½ÃæµÃµ½Á˺ܶàÌá¸ß£¬ÓÈÆäÊDZí·ÖÇøµÄ¼¼Êõ¡£Èç¹ûÄ㻹û²»Á˽â±í·ÖÇøµÄÌØÕ÷£¬ÄÇôÇëÄ㻨µã ......
ÓÃsql*plus»òµÚÈý·½¿ÉÒÔÔËÐÐsqlÓï¾äµÄ³ÌÐòµÇ¼Êý¾Ý¿â£º
Ôö¼ÓÒ»¸öÁУº
ALTER TABLE ±íÃû ADD(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp ADD(weight NUMBER(38,0));
ÐÞ¸ÄÒ»¸öÁеÄÊý¾ÝÀàÐÍ(Ò»°ãÏÞÓÚÐ޸ij¤¶È£¬ÐÞ¸ÄΪһ¸ö²»Í¬ÀàÐÍʱÓÐÖî¶àÏÞÖÆ):
ALTER TABLE ±íÃû MODIFY(ÁÐÃû Êý¾ÝÀàÐÍ);
È磺
ALTER TABLE emp MODIFY(wei ......