SQL COUNTµÄÓ÷¨
ÔÚÉÏÒ»Ò³ÓÐÌáµ½£¬COUNT ÊǺ¯ÊýÖ®Ò»¡£ÓÉÓÚËüµÄʹÓù㷺£¬ÎÒÃÇÔÚÕâÀïÌØ±ðÌá³öÀ´ÌÖÂÛ¡£»ù±¾ÉÏ£¬COUNT ÈÃÎÒÃÇÄܹ»Êý³öÔÚ±í¸ñÖÐÓжàÉÙ±Ê×ÊÁϱ»Ñ¡³öÀ´¡£ËüµÄÓï·¨ÊÇ£º
SELECT COUNT("À¸Î»Ãû")
from "±í¸ñÃû"
¾ÙÀýÀ´Ëµ£¬ÈôÎÒÃÇÒªÕÒ³öÎÒÃǵÄʾ·¶±í¸ñÖÐÓм¸±Ê store_name À¸²»Êǿհ׵Ä×ÊÁÏʱ£¬
Store_Information ±í¸ñ
store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
Los Angeles
$300
Jan-08-1999
Boston
$700
Jan-08-1999
ÎÒÃǾʹòÈ룬
SELECT COUNT(store_name)
from Store_Information
WHERE store_name is not NULL
½á¹û:
Count(store_name)
4
"is not NULL" ÊÇ "Õâ¸öÀ¸Î»²»Êǿհ×" µÄÒâ˼¡£
COUNT ºÍ DISTINCT ¾³£±»ºÏÆðÀ´Ê¹Óã¬Ä¿µÄÊÇÕÒ³ö±í¸ñÖÐÓжàÉٱʲ»Í¬µÄ×ÊÁÏ (ÖÁÓÚÕâЩ×ÊÁÏʵ¼ÊÉÏÊÇʲô²¢²»ÖØÒª)¡£ ¾ÙÀýÀ´Ëµ£¬Èç¹ûÎÒÃÇÒªÕÒ³öÎÒÃǵıí¸ñÖÐÓжàÉÙ¸ö²»Í¬µÄ store_name£¬ÎÒÃǾʹòÈ룬
SELECT COUNT(DISTINCT store_name)
from Store_Information
½á¹û:
Count(DISTINCT store_name)
3
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃæ£¬ºóÃæ ......
ÓÃjdbcÁ¬½ÓSQL Server2005³öÏÖµ½Ö÷»ú µÄ TCP/IP Á¬½Óʧ°Ü¡£ java.net.ConnectException: Connection refused: connect!
¹À¼ÆÊÇÒòΪsqlserver2005ĬÈÏÇé¿öÏÂÊǽûÓÃÁËtcp/ipÁ¬½Ó¡£
Äú¿ÉÒÔÔÚÃüÁîÐÐÊäÈ룺telnet localhost 1433½øÐмì²é£¬Õâʱ»á±¨´í£ºÕýÔÚÁ¬½Óµ½localhost...²»ÄÜ´ò¿ªµ½Ö÷»úµÄÁ¬½Ó£¬ÔÚ¶Ë¿Ú 1433: Á¬½Óʧ°Ü
Æ ......
SQLÓï¾äÓÅ»¯¼¼Êõ·ÖÎö
×î½ü¼¸ÖÜÒ»Ö±ÔÚ½øÐÐÊý¾Ý¿âÅàѵ£¬ÀÏʦ¾«Õ¿µÄ¼¼ÊõºÍÉú¶¯µÄ½²½âʹÎÒÊÜÒæ·Ëdz¡£ÎªÁËÈøü¶àµÄÐÂÊÖÊÜÒæ£¬ÎÒ³é¿Õ°ÑSQLÓï¾äÓÅ»¯²¿·Ö½øÐÐÁËÕûÀí£¬Ï£Íû´ó¼ÒÒ»Æð½ø²½¡£
Ò»¡¢²Ù×÷·ûÓÅ»¯
1¡¢IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ×¶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊÇ±È½Ï ......
IN Õâ¸öÖ¸Áî¿ÉÒÔÈÃÎÒÃÇÒÀÕÕÒ»»òÊý¸ö²»Á¬Ðø (discrete) µÄÖµµÄÏÞÖÆÖ®ÄÚ×¥³öÊý¾Ý¿âÖеÄÖµ£¬¶ø BETWEEN ÔòÊÇÈÃÎÒÃÇ¿ÉÒÔÔËÓÃÒ»¸ö·¶Î§ (range) ÄÚ×¥³öÊý¾Ý¿âÖеÄÖµ¡£BETWEENÕâ¸ö×Ó¾äµÄÓï·¨ÈçÏ£º
SELECT "À¸Î»Ãû"
from " ±í¸ñÃû"
WHERE "À¸Î»Ãû" BETWEEN 'ÖµÒ»' AND 'Öµ¶þ'
Õ⽫ѡ³öÀ¸Î»Öµ°üº¬ÔÚÖµÒ»¼°Öµ¶þÖ®¼äµÄÿһ±Ê× ......
¼ÈÈ»Êý¾Ý¿âÖÐÓÐÐí¶à×ÊÁ϶¼ÊÇÒÑÊý×ÖµÄÐÍ̬´æÔÚ£¬Ò»¸öºÜÖØÒªµÄÓÃ;¾ÍÊÇÒªÄܹ»¶ÔÕâЩÊý×Ö×öһЩÔËË㣬ÀýÈ罫ËüÃÇ×ÜºÏÆðÀ´£¬»òÊÇÕÒ³öËüÃÇµÄÆ½¾ùÖµ¡£SQL ÓÐÌṩһЩÕâÒ»ÀàµÄº¯Êý¡£ËüÃÇÊÇ£º
AVG (ƽ¾ù)
COUNT (¼ÆÊý)
MAX (×î´óÖµ)
MIN (×îСֵ)
SUM (×ܺÏ)
ÔËÓú¯ÊýµÄÓï·¨ÊÇ£º
SELECT "º¯ÊýÃû"("À¸Î»Ãû")
from "± ......