sql语句含义

来源:百度知道 编辑:UC知道 时间:2024/06/02 12:47:36
update da_czk set ye=ye-zckxf.xf from
(select id as card_no ,sum(amt) as xf from xs_003 where id<>'' and bdate='2007-03-08'
group by id
) zckxf where da_czk.card_no=zckxf.card_no

select id as card_no ,sum(amt) as xf from xs_003 where id<>'' and bdate='2007-03-08'
group by id
第一我们先看这句话:
这是用id分组,取 amt字段的和,且id不能为空,和日期bdate是2007-03-08的.这个查询可以出来一个结果集合,我们给他起名为:zckxf
这样我们的sql语句就变成了:

update da_czk set ye=ye-zckxf.xf from
zckxf where da_czk.card_no=zckxf.card_no
这样我们就能看懂了
通过card_no把da_czk和我们刚才取的结果集(zckxf)card_no相同的项目,把da_czk的ye字段更新,更新为本身再减去我们取的数据集(zckxf)里的xf字段。

update da_czk set ye=ye-zckxf.xf from
(select id as card_no ,sum(amt) as xf from xs_003 where id<>'' and bdate='2007-03-08'
group by id
) zckxf where da_czk.card_no=zckxf.card_no

1.update da_czk set ye=ye-zckxf.xf 设置ye字段的值
2.from
(select id as card_no ,sum(amt) as xf from xs_003 where id<>'' and bdate='2007-03-08'
group by id
)
按ID分组且日期为2007-03-08的XS_003表中总计产生的表
3.where da_czk.card_no=zckxf.card_no
对生成的表再加一判断