SQL工作记录

两张表是一样的,只是新老数据更新
update dbo.classmates
set LoginTimes = (select LoginTimes from dbo.classmates2 where classmates.id = classmates2.id )

select 输出格式化(分支判断)注意字串用单引号
select name 名字, (case when sex=1 then '男' else '女' end)性别 from classmates

联接(二表)更新

update charge_mst
set receipt = receipt - k.allDot
from charge_mst as c,kao600099 as k
where k.inuser = c.userid


把“回复表”里的回复时更表到“留言表”里去(置疑)
UPDATE guestbook INNER JOIN Reply ON guestbook.PostID = Reply.PostID SET guestbook.dtLastReply = Reply.ReplyTime
WHERE [Reply].[PostId] =[guestbook].[PostId]

复制表
select * into b from a

拷贝表
insert into b(a, b, c) select d, e, f from b

你可能感兴趣的:(JOIN,sql,c,工作,insert)