一很有度的sql
select pnl,date_piece,model_no,factsal
from wg_yyjz
where date_piece like '200703% ';
----------------------------------------------
pnl date_piece model_no factsal
0543120070301PM-19276.69
0543420070312BM-7871.53
054612007032213055.16
0546120070322-00255.16
054612007032219255.16
0547920070324-192-156.38
05485200703257866.59
05488200703287857.08
054882007032878.157.08
-------------------------------------------
我想得到的果是:
(相同工同一天不同model_no工人(pnl)的factsal有重(因量大,可能有多重factsal)
的就值0,只保留一factsal(一天的工值))
-------------------------------------------
pnl date_piece model_no factsal
0543120070301PM-19276.69
0543420070312BM-7871.53
054612007032213055.16
0546120070322-0020
05461200703221920
0547920070324-192-156.38
05485200703257866.59
05488200703287857.08
054882007032878.10
-------------------------------------------
怎?help!
[解决办法]
--保留model_no相最小的一:
update wg_yyjz
set factsal=0
where date_piece like '200703% '
and exists(select 1 from wg_yyjz a
where a.pnl=wg_yyjz.pnl
and a.date_piece=wg_yyjz.dete_piece
and a.factsal=wg_yyjz.factsal
and a.model_no <wg_yyjz.model_no)