sql·Ö×麯ÊýʹÓÃ
ת×Ô£ºhttp://book.csdn.net/bookfiles/235/10023510864.shtml
ÔÚʵ¼ÊSQLÓ¦ÓÃÖУ¬¾³£ÐèÒª½øÐзÖ×é¾ÛºÏ£¬¼´½«²éѯ¶ÔÏó°´Ò»¶¨Ìõ¼þ·Ö×飬Ȼºó¶Ôÿһ¸ö×é½øÐоۺϷÖÎö¡£
GROUP BY×Ӿ䴴½¨·Ö×é
´´½¨·Ö×éÊÇͨ¹ýGROUP BY×Ó¾äʵÏֵġ£ÓëWHERE×Ӿ䲻ͬ£¬GROUP BY×Ó¾äÓÃÓÚ¹éÄÉÐÅÏ¢ÀàÐÍ£¬ÒÔ»ã×ÜÏà¹ØÊý¾Ý¡£¶øΪʲôҪʹÓÃGROUP BY×Ӿ䴴½¨·Ö×éÄØ£¿¿Éͨ¹ýÏÂÃæÕâ¸ö¼òµ¥Àý×ÓÀ´ËµÃ÷¡£
ʵÀý17 µ¥Ò»·Ö×éµÄ²éѯ
¼ÙÈçÒª´ÓTEACHER±íÖвéѯËùÓÐÄнÌʦµÄƽ¾ù¹¤×Ê£¬ÓÃÇ°Ãæ½éÉܵľۺϺ¯ÊýAVG(),ʵÏÖ´úÂëÈçÏ£º
SELECT AVG(SAL) AS boyavg_sal
from TEACHER
WHERE TSEX='ÄÐ'
ÔËÐнá¹ûÈçͼ8.18Ëùʾ¡£
ͼ8.18 TEACHER±íÖвéѯËùÓÐÄнÌʦµÄƽ¾ù¹¤×Ê
¶øÈç¹ûͬʱÐèÒª²éѯËùÓÐÅ®½ÌʦµÄƽ¾ù¹¤×Ê£¬¸ÃÈçºÎ´¦ÀíÄØ£¿ÏÔÈ»£¬²ÉÓÃÉÏÊö·½·¨Ö»ÄÜÔÚWHERE×Ó¾äÖиıä²éѯÌõ¼þ£¬ÖØвéѯ¡£¶øÈç¹ûÒªÔÚÒ»´Î²éѯÖУ¬Í¬Ê±µÃµ½¶þÕߵIJéѯ½á¹û£¬¾ÍÐèÒªÒÔÐÔ±ðΪ»ù×¼£¬½«±íÖеÄËùÓÐÊý¾Ý¼Ç¼·Ö×飬¼´ÄнÌʦ×éºÍÅ®½Ìʦ×飬²¢·Ö±ð¶ÔÁ½×éÊý¾Ý½øÐзÖÎö£¬¼´¼ÆË㹤×Ê£¨SALÁУ©µÄƽ¾ùÖµ¡£
ʵÏÖÉÏÊö¹¦ÄÜ£¬¾ÍÐèҪʹÓ÷Ö×é×Ó¾äGROUP BY¡£°üÀ¨GROUP BY×Ó¾äµÄ²éѯ¾Í³ÆΪ×éºÏ²éѯ¡£Óï·¨ÈçÏ¡£
SELECT column, SUM(column)
from table
GROUP BY column
˵Ã÷£ºGROUP BY×Ó¾äÒÀ¾ÝcolumnÁÐÀïµÄÊý¾Ý¶ÔÐнøÐзÖ×飬¼´¾ßÓÐÏàͬµÄÖµµÄÐб»»®ÎªÒ»×é¡£ËüÒ»°ãÓë¾ÛºÏº¯ÊýͬʱʹÓᣵ±È»£¬ÕâÀïµÄSUM()º¯ÊýÒ²¿ÉÒÔÊÇÆäËû¾ÛºÏº¯Êý¡£ËùÓеÄ×éºÏÁУ¨GROUP BY×Ó¾äÖÐÁгöµÄÁУ©±ØÐëÊÇÀ´×Ôfrom×Ó¾äÁгöµÄ±í£¬²»Äܸù¾Ýʵ¼ÊÖµ¡¢¾ÛºÏº¯Êý½á¹û»òÕßÆäËû±í´ïʽ¼ÆËãµÄÖµÀ´¶ÔÐзÖ×é¡£
ʵÀý18 GROUP BY×Ó¾ä·Ö×é²éѯ
´ÓTEACHER±íÖвéѯËùÓÐÄнÌʦµÄƽ¾ù¹¤×ʺÍËùÓÐÅ®½ÌʦµÄƽ¾ù¹¤×Ê£¬ÊµÏÖ´úÂëÈçÏ¡£
SELECT TSEX+'½Ìʦ'AS TEACHER, AVG(SAL) AS avg_sal
from &nb
Ïà¹ØÎĵµ£º
×òÌìŪÁËÒ»¸ö±È½Ï¼¬ÊÖµÄÎÊÌâ¡£´ÓÍøÉÏÏÂÔØÁËÒ»¸öÈí¼þ£¬ËûµÄÊý¾Ý¿âÊÇaccessµÄ£¬´ò¿ª¿´ÁËһϣ¬¸Ð¾õ²»´í£¬ÊʺÏÎÒÏÖÔÚÏîÄ¿µÄÐèÇ󣬴󲿷ÖÄܹ»Âú×ãÎÒµÄÏîÄ¿ÐèÒª£¬¾ÍÏëÄÃÀ´Ö÷Òå¡£¿ÉÊÇÎÒÃÇÏîÄ¿µÄÊý¾Ý¿âÒ»Ö±¶¼ÊÇÓõÄsqlserver£¬ÓÚÊÇ£¬¾ÍÔÚÍøÉÏ·è¿ñµÄ£¬ÕÒ¹ØÓÚaccessת»»ÎªsqlserverµÄ×ÊÁÏÔÚÕâÀïÎÒÏë˵һÏÂÓйصÄ×¢ÒâÊÂÏ
Êý¾Ý¿âÉý ......
sqldataadapterÊʺÏÓÃÔÚ²éѯ½Ï¶à×Ö¶Îʱ.....
string sou = "select * from art where content like '%" + TextBox1.Text + "%'";
SqlDataAdapter da = new SqlDataAdapter(sou, conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].rows.count==0)
{
Response.Write("ûÓмǼ£¡");
}
else
{
......
if exists(select * from sysobjects where name='atzk')--ÅжÏÊÇ·ñ´æÔڴ˱í
drop table atzk
go
create table atzk
(
nid int identity(1,1) primary key,--nid×Ô¶¯±àºÅ£¬²¢ÉèΪÖ÷¼ü¡£
mytitle varchar(50) not null,--֪ͨµÄ±êÌâ¡£
mycontents varchar(200)--·¢²¼Í¨ÖªµÄÄÚÈÝ¡£
) ......
Èç¹ûÄãµÄÊý¾Ý¿âÔËÐÐÔÚÍêÕû»òÊÇÅúÁ¿ÈÕÖ¾»Ö¸´Ä£Ê½Ï£¬ÄÇôÄã¾ÍÐèҪʹÓÃ×÷Òµ(job)À´¶¨ÆÚ±¸·ÝÊÂÎñÈÕÖ¾£¬±£³ÖÄãµÄÊÂÎñÎļþ´óС´¦ÔÚÒ»¸ö¿É¹ÜÀíµÄ·¶Î§¡£µ±ÄãÐèÒª»¹ÔÊÂÎñÈÕ־ʱ£¬Äã¾ÍÐèÒª°´ÕÕ´´½¨ÊÂÎñÈÕÖ¾µÄ˳ÐòÀ´»Ö¸´ËüÃÇ¡£Äã¿ÉÒԲο¼´æÔÚmsdb..backupset±íÖеÄÐÅÏ¢À´È·¶¨»¹ÔÎļþµÄ˳Ðò£¬Ê¹ÓÃFirstLSNºÍLastLSNÁеÄÖµ×÷²Î¿¼¡£µ±Ä ......