1.sql修改表中某字段的值来自另一张表中的数据(sql update select)
UPDATE 表1 set 表1.erpid = b.erpid FROM (select memberid,erpid from 表2) b WHERE b.memberid = 表1.member_id
2.sql根据字段分组,且查询多个字段
select member_erpid,dwmc,lxr,lxdh,ywyID,d.username from member_cart a left join members b on a.member_erpid=b.erpid eft join members_item c on a.member_erpid=c.erpid left join admin d on c.ywyID=d.id group by a.member_erpid ,dwmc,lxr,lxdh,ywyID,d.username
3.sql查询时间段的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())=0--查询今天的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())<=7--查询近一周的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())<=30--查询近一月的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())<=90--查询近三月的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())<=180--查询近半年月的数据
select addtime,yx,* from [order] where DateDiff(dd,addtime,getdate())<=365--查询近一年的数据
select addtime,yx,ddzt,* from [order] where DateDiff(dd,addtime,getdate())>365--查询一年以前的数据