id attr id_choosed attr_count 1 a 1 0 2 a 1 0 3 a 0 0 4 b 1 0 5 b 1 0 当满足某条件后,id被选中,更新id_choosed 和attr_count 如下: 更新后 id attr id_choosed attr_count 1 a 1 2 2 a 1 2 3 a 0 0 4 b 1 2 5 b 1 2 这样的update语句怎么写?
那你在程序里面将选中的记录存入一个字符串数组里面(TStrings) 然后用个循环不就把所选中的记录更新了啊 var sL: TStrings; I: Integer; begin sl:= TstringList.create; { //加入选中的ID sL.add();} for I := 0 to sL.count-1 do begin with adoQuery do begin close; sql.text:= 'update TableName set id_choosed = 1, attr_count={你要更新的值} where id = ' + QuotedStr(sl.string[i]); execsql; end; end;
我原来是这样写的: update tablename A,TT set A.attr_count=A.attr_count+1 where A.id=TT.id and A.attr_count<2 其中TT是临时表,是所有id_Choosed=1的临时表问题是这样更新后,tablename表的attr_count都是1,
id_choosed:1为该id被选中,0为未被选中
attr_count:相同类别的被选中的个数这样的sql怎么写?
(select count(*) from tableName where attr='a')
数据量很大的,不能这样写
你应该是要在程序里面实现:
选中了N条记录,然后要将选中的记录的id_choosed,attr_count更新
是吧?
是的啊,
然后用个循环不就把所选中的记录更新了啊
var
sL: TStrings;
I: Integer;
begin
sl:= TstringList.create;
{ //加入选中的ID
sL.add();}
for I := 0 to sL.count-1 do
begin
with adoQuery do
begin
close;
sql.text:= 'update TableName set id_choosed = 1, attr_count={你要更新的值} where id = ' + QuotedStr(sl.string[i]);
execsql;
end;
end;
update tablename A,TT set A.attr_count=A.attr_count+1
where A.id=TT.id and A.attr_count<2
其中TT是临时表,是所有id_Choosed=1的临时表问题是这样更新后,tablename表的attr_count都是1,