表结构如下:
rq(日期) rkje(入库金额) ckje(出库金额) kcje(库存金额)表中rq,rkje,ckje字段都是有内容的,kcje字段都为空。
表中的日期字段是一号到当月的最后一天的所有日期。由于每月的最后一天不确定,有的是28号。30号或者31号。我现在要向这个表中的日期最大的那条记录插入kcje的数据,该怎么写语句?
rq(日期) rkje(入库金额) ckje(出库金额) kcje(库存金额)表中rq,rkje,ckje字段都是有内容的,kcje字段都为空。
表中的日期字段是一号到当月的最后一天的所有日期。由于每月的最后一天不确定,有的是28号。30号或者31号。我现在要向这个表中的日期最大的那条记录插入kcje的数据,该怎么写语句?
update tb set kcje=@kcje where rq=(select max(rq) from tb)
update tb
set kcje = @kcje
where rq = (select max(rq) from tb where convert(varchar(6),rq,112) = '201101') --2011年1月份最大的。
update tablename set kcje=123 where rq=select max(rq) from tablename
set kcje = ...
from tb t where rq = (select max(rq) from tb where datediff(mm,rq,t.rq) = 0)update tb
set kcje = ...
from tb t where not exists (select 1 from tb where datediff(mm,rq,t.rq) = 0 and rq > t.rq)
set kcje=XXX where
rq in
(
select ayear + '-' + amonth + '-' + aday From (
select ayear,amonth,max(aday) aday from (
select year(rq) ayear ,month(rq) amonth,day(rq) aday from tableaa
) aaa group by ayear,amonth
) aa
)
update tb set kcje=@kcje where rq=(select max(rq) from tb)