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
Ïà¹ØÎĵµ£º
Q£º±ßÉϵÄͬÊÂ˵Îļþ×é°üº¬¶à¸öÎļþ¿ÉÒÔÔö¼Ó²¢Ðжȣ¬Ò²¾ÍÊǶà¸öCPU¿ÉÒÔÒ»Æð¶Á£¿
A£º¿ÉÒÔÔö¼Ó²¢Ðжȣ¬µ«Ç°ÌáÊÇÊý¾Ý¿â¿ÉÒÔÖ§³Ö¶àÏ̷߳ÃÎʲ»Í¬µÄ·ÖÇø£¬¾Ý˵2005µÄ·ÖÇø±í²¢²»ÊÇÿ¸ö·ÖÇø¶¼·ÖÅäÒ»¸öỊ̈߳¬µ«ÊÇ2008òËƾÍÊÇ¡£Æä´Î£¬Èç¹ûÊǶàCPU£¬¶à´ÅÅÌ£¬»áÔö¼Ó²¢Ðжȵġ£¶à¸öCPUÒ»Æð¶ÁÒ²Òª¿´ÕâЩ¶à¸öÎļþÊDz»ÊÇ·ÅÔÚÒ»¸ö ......
SELECT Ö¸ÁîÈÃÎÒÃÇÄܹ»¶ÁÈ¡±í¸ñÖÐÒ»¸ö»òÊý¸öÀ¸Î»µÄËùÓÐ×ÊÁÏ¡£ Õ⽫°ÑËùÓеÄ×ÊÁ϶¼×¥³ö£¬ÎÞÂÛ×ÊÁÏÖµÓÐÎÞÖظ´¡£ÔÚ×ÊÁÏ´¦ÀíÖУ¬ÎÒÃǻᾳ£Åöµ½ÐèÒªÕÒ³ö±í¸ñÄڵIJ»Í¬ ×ÊÁÏÖµµÄÇé¿ö¡£»»¾ä»°Ëµ£¬ÎÒÃÇÐèÒªÖªµÀÕâ¸ö±í¸ñ/À¸Î»ÄÚÓÐÄÄЩ²»Í¬µÄÖµ£¬¶øÿ¸öÖµ³öÏֵĴÎÊý²¢²»ÖØÒª¡£ÕâÒªÈçºÎ´ï³ÉÄØ£¿ÔÚ SQL ÖУ¬ÕâÊǺÜÈÝÒ××öµ½µÄ¡£ÎÒÃÇÖ»ÒªÔ ......
ÎÒÃDz¢²»Ò»¶¨Ã¿Ò»´Î¶¼Òª½«±í¸ñÄÚµÄ×ÊÁ϶¼Íêȫץ³ö¡£ÔÚÐí¶àʱºò£¬ÎÒÃÇ»áÐèҪѡÔñÐÔµØ×¥×ÊÁÏ¡£¾ÍÎÒÃǵÄÀý×ÓÀ´Ëµ£¬ÎÒÃÇ¿ÉÄÜֻҪץ³öÓªÒµ¶î³¬¹ý $1,000 µÄ×ÊÁÏ¡£Òª×öµ½ÕâÒ»µã£¬ÎÒÃǾÍÐèÒªÓõ½ WHERE Õâ¸öÖ¸Áî¡£Õâ¸öÖ¸ÁîµÄÓï·¨ÈçÏ£º
SELECT "À¸Î»Ãû"
from "±í¸ñÃû"
WHERE "Ìõ¼þ"
ÈôÎÒÃÇÒªÓÉÒÔϵıí¸ñ×¥³öÓªÒµ¶î³¬¹ý $1, ......
IN Õâ¸öÖ¸Áî¿ÉÒÔÈÃÎÒÃÇÒÀÕÕÒ»»òÊý¸ö²»Á¬Ðø (discrete) µÄÖµµÄÏÞÖÆÖ®ÄÚ×¥³öÊý¾Ý¿âÖеÄÖµ£¬¶ø BETWEEN ÔòÊÇÈÃÎÒÃÇ¿ÉÒÔÔËÓÃÒ»¸ö·¶Î§ (range) ÄÚ×¥³öÊý¾Ý¿âÖеÄÖµ¡£BETWEENÕâ¸ö×Ó¾äµÄÓï·¨ÈçÏ£º
SELECT "À¸Î»Ãû"
from " ±í¸ñÃû"
WHERE "À¸Î»Ãû" BETWEEN 'ÖµÒ»' AND 'Öµ¶þ'
Õ⽫ѡ³öÀ¸Î»Öµ°üº¬ÔÚÖµÒ»¼°Öµ¶þÖ®¼äµÄÿһ±Ê× ......