sqlÓï¾äÎÊÌâ - MS-SQL Server / Ó¦ÓÃʵÀý
ÓÐÒ»¸ö±í£¬´æ·ÅµÄÊÇѧÉúµÄ³É¼¨£¬
Íê³ÉÈçϹ¦ÄÜ£º
Èç¹ûÒ»¸öѧÉúµÄijÃſγ̵ijɼ¨µÍÓÚ¸ÃÃÅ¿Î³ÌµÄÆ½¾ù³É¼¨£¬½«ËûµÄ³É¼¨Ìá¸ß5%
s_c(sid,cid,score)
sidѧºÅ
cid ¿Î³ÌºÅ
score³É¼¨
SQL code:
update s set s.score=1.05*score
from s_c s
join
(select cid,avg(score) as avgscore
from s_c
Group by cid) c on s.cid=c.cid and s.score<c.avgscore
SQL code:
create table s_c(sid int,cid int,score int)
insert s_c
select 1,1,40 union all
select 2,1,50 union all
select 3,1,60 union all
select 1,2,50 union all
select 2,2,60 union all
select 3,2,70
select * from s_c t
where score<(select avg(score) from s_c where cid=t.cid group by cid)
/*
sid cid score
----------- ----------- -----------
1 1 40
1 2 50
£¨ËùÓ°ÏìµÄÐÐÊýΪ 2 ÐУ©*/
update t set score = score*1.05
from s_c t
where score<(select avg(score) from s_c where cid=t.cid group by cid)
select * from s_c
/*
sid cid score
----------- ----------- -----------
1 1 42
2 1 50
3 1 60
1 2 52
2 2 60
3 2 70
£¨ËùÓ°ÏìµÄÐÐÊýΪ 6 ÐУ©
*/
Ïà¹ØÎÊ´ð£º
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
½ñÌì×öÁËÒ»¸ö´æ´¢¹ý³Ì »·¾³ÊÇSQL2000Êý¾Ý¿â
´óÖÂÈçÏÂ
½¨Á¢ÁÙʱ±í
¶¨ÒåÔ±¹¤Óαê
Ñ»·Ô±¹¤£¨ÊôÓÚ1¸ö¹«Ë¾)
......
select count(1) from FX_RETURNBOOKCHECKLIST fxreturnbo0_ where fxreturnbo0_.BOOKID='164 ' AND fxreturnbo0_.RETURNID='00025.S0000001'
ÉÏÃæÒ»¸ö¼òµ¥µÄSQL,Ö´ÐÐʱ¼ä2.6à ......
ÈçºÎÔÚSQL2005ÖÐÉ趨¶¨Ê±×÷Òµ£¬±ÈÈç˵¶¨Ê±ÇåÀíijЩ±íµÄÊý¾Ý£¬
»òÕßÊǶ¨Ê±µÄ½«Ä³Ð©±íµÄÊý¾Ýµ¼³öexcel£¡
ÔÚÏߵȴý£¬¼±¼±¼±£¬×îºÃÊÇÏêϸ²½Ö裡
֮ǰÎÒ×öµÄ×÷ÒµÓеãÎÊÌ⣡
°ïUP
²Î¿¼:http://hi.baidu.com/toiota ......
tab1 ×Ö¶Î:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 ×Ö¶Î:goodsid,goodskind£¨ÉÌÆ·ÀàÐÍ£©
tab3 ×Ö¶Î:goodskind£¨ÉÌÆ·ÀàÐÍ£©,kindname
½á¹û£º
µÃµ½ÉÌÆ·ÀàÐÍÔÚÒ»¶Îʱ¼ä ......