SQL³£ÓÃÓï¾ä
1¡¢Óëgroup by´îÅäʹÓõĺ¯Êý
ÔÚÊý¾Ý¿âÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃGROUP BYº¯Êý°ÑÊý¾Ý×éºÏÔÚÒ»Æ𣬴Ӷø»ñµÃ×ܼÆÐÅÏ¢¡£¿ÉÒ԰Ѵ˹¦ÄÜ¿´³ÉÊÇÒ»ÖÖµ±Êý¾Ý´ÓÊý¾Ý¿âÖзµ»Øʱ°ÑÏàͬÀàÐ͵ÄÐÅÏ¢¼¯Öе½Ò»ÆðµÄÄÜÁ¦¡£ÏÂÃæ¸ø³öÁËÍêÕûÁÐ±í¡£
avg([distinct]column_name)
ÇóËùÓйÍԱнˮµÄƽ¾ùÖµ¡£
select AVG(emp_salary)
from employee;
ÇóÈ¡column_nameÖеÄËùÓÐÖµµÄƽ¾ùÖµ¡£Èç¹ûʹÓÃDISTINCTÑ¡ÏÔòֻʹÓò»Í¬µÄ·Ç¿ÕµÄÊýÖµ¡£
count([distinct]value)
ͳ¼Æ¹ÍÔ±µÄÊýÄ¿¡£
select COUNT(emp_name)
from employee;
ͳ¼ÆÑ¡ÔñÐеÄÊýÄ¿£¬²¢ºöÂÔVALUEÖеĿÕÖµ¡£Èç¹ûʹÓÃÁËDISTINCTÑ¡Ïî
Ôòֻͳ¼Æ²»Í¬µÄ·Ç¿ÕÊýÖµ¡£VALUE¿ÉÒÔÊÇÁÐÃû£¬Ò²¿ÉÒÔÊDZí´ïʽ¡£
max(value)
·µ»ØнˮµÄ×î´óÖµ
select MIN
emp_salary)
from employee;
´ÓÑ¡¶¨µÄVALUEÖÐÑ¡³öÊýÖµ/×Ö·ûµÄ×î´óÖµ£¬ºöÂÔ¿ÕÖµ¡£VALUEÒªÇóͬÉÏ¡£
min(value)
·µ»ØнˮµÄ×îСֵ
select MIN(emp_salsry)
from employee;
´ÓÑ¡¶¨µÄVALUEÖÐÑ¡³öÊýÖµ/×Ö·ûµÄ×îСֵ£¬ºöÂÔ¿ÕÖµ¡£VALUEÒªÇóͬÉÏ¡£
stddev(value)·µ»Ø¹ÍԱнˮµÄ±ê׼ƫ²î
select STDDEV(emp_salary)
from employee;
´ÓÑ¡ÔñµÄVALUEµÄ±ê×¼Öзµ»Ø±ê׼ƫ²î¡£
variance([distinct]value)
·µ»Ø¹ÍԱнˮµÄ·½²î
select VARIANCE(emp_salary)
from employee;
·µ»ØËùÑ¡ÐеÄËùÓÐÊýÖµµÄ·½²î£¬ºöÂÔVALUEµÄ¿ÕÖµ¡£DISTINCTºÍVALUEÒª
Çóͬǰ¡£
2¡¢Öµ×ª»»£¨case……when……then……else……end£©
select name as ÐÕÃû,case sex when boy then ÄÐ else Å® end as ÐÔ±ð from student;
½«²éѯ³öµÄÐÔ±ðboyת»»ÎªÄУ¬ÆäËüµÄת»»ÎªÅ®¡£
Ïà¹ØÎĵµ£º
SQL SERVER2000´ò²¹¶¡ÎÊÌâ»ã×Ü ¡¾http://hi.baidu.com/yanhai/blog/item/cf67c2ce07a9f50992457e9d.html¡¿
SQL ServerµÄ²¹¶¡°æ±¾¼ì²é²»ÈçWindows ²¹¶¡°æ±¾¼ì²éÖ±½Ó£¬Ò»¸öϵͳ¹ÜÀíÔ±£¬Èç¹û²»Á˽âSQL Server°æ±¾¶ÔÓ¦µÄ²¹¶¡ºÅ£¬¿ÉÄÜÒ²»áÓöµ½Ò»µãÂé·³£¬Òò´ËÔÚÕâ˵Ã÷һϣ¬Í¨¹ýÕâÑùµÄ°ì·¨Åбð»úÆ÷ÊÇ°²È«µÄ°ì·¨£¬²»»á¶Ôϵͳ²úÉúÈ ......
¼à¿ØÊý¾Ý¿âÐÔÄܵÄSQL»ã×Ü ¡¾http://hi.baidu.com/g%5Fliying/blog/item/89711cfc27b82ff4fc037f80.html¡¿
1. ¼à¿ØÊÂÀýµÄµÈ´ý
select event,sum(decode(wait_Time,0,0,1)) "Prev",
sum(decode(wait_Time,0,1,0)) "Curr",count(*) "Tot"
from v$session_Wait
group by event order by 4;
2. »Ø¹ö¶ÎµÄÕùÓÃÇé¿ö
se ......
ÎÊÌâÃèÊö£ºÓÐÒÔÏÂ2ÕÅ±í£¬
±íA
& ......
ÎÄÖеÄSQL¶¼ÊÇ´ÓÎÒµÄÏîÄ¿ÖÐÖ±½Ócopy¹ýÀ´£¬Òò´ËºÜ¶à±íÃûʲô¶¼ÓÐÁË
//´´½¨±í
"CREATE TABLE FEED_TABLE(FeedID TEXT, Title TEXT, Summary TEXT, Author TEXT, ImageName VARCHAR(21), ImageType TEXT, MaxIndex INT, ImageData BLOB)"
//²éѯ¼Ç¼
"select * form 'table_name'"
"select * form 'table name' where val ......
2¡¢sql express °²×° Èç¹ûÔÚXPÏ£¬Ö±½ÓË«»÷°²×°¾ÍºÃÁË¡£ ÏÈ°²×° [ÔÚvistaÏÂÈç¹ûÖ±½ÓË«»÷¿ÉÄÜ»á³öÏÖ °²×°sql server express ³ö´í29506 ] [Vista°²×°µÄʱºò£¬ÐèҪʹÓá°ÒÔ¹ÜÀíÔ±Éí·ÝÔËÐС±°²×°] SQLServer2005_SSMSEE.msi°²×°½áÊø studioÒѾ°²×°ÉÏÈ¥£¬µ«ÊÇÄãÓÐûÓз¢ÏÖ£¬°²×°sqlµÄʱºòûÓз¢ÏÖÓÐÓû§saµÄà ......