SQL语句整理

1、问题贴见(这里一个注意点为:coalesce(字段,0) 使用,即判断这个字段是否为NULL,如果为NULL,则为0)

http://topic.csdn.net/u/20121022/17/4b3a512f-e329-4b03-8aae-d4ce9c9c43f4.html?seed=1876494661&r=79962941#r_79962941


select tt.uname,tt.sumstart,ttt.laststart from
(
     select id,name as uname, COALESCE(SUM(start),0) as sumstart from [user] t1 left join team t2
     on t1.id=t2.uid  group by id,name
) tt,
(
     select t1.id,t1.name as uname, COALESCE(start,0)as laststart from [user] t1 left join team t2
     on t1.id=t2.uid and data=(select MAX(data) from team)
) ttt
where tt.id=ttt.id;

SQL语句整理_第1张图片



级联更新表字段

update ST_PPTN_D  set LGTD= a.LGTD,LTTD=a.LTTD 
from ST_STBPRP_B a  inner join ST_PPTN_D p on p.STCD=a.STCD; 



你可能感兴趣的:(SQL语句整理)