天 天真 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #1 假如我有A表 ID FY 1 2 3 3 1 5 2 1 如何用SQL语句使其变为 ID FY 1 7 2 1 3 3 越简单越好
J jqw Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #2 update A set (ID,FY)=(select ID,SUM(FY) FROM A GROUP BY ID); 在ORACLE中肯定行
Y yzhshi Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #6 肯定不会成功,最好是从一个表中搞到另一个表中。 否则需要删除记录,一条SQL实现比较复杂了。尤其是含有主键的情况。
Y yzhshi Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #7 对了,使用两个表,jqw的SQL稍加改动就应该成了。 Insert into Table2 (ID,FY) (select ID,SUM(FY) FROM A GROUP BY ID)(没有具体实验呀。)
对了,使用两个表,jqw的SQL稍加改动就应该成了。 Insert into Table2 (ID,FY) (select ID,SUM(FY) FROM A GROUP BY ID)(没有具体实验呀。)
秋 秋之叶 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #9 Select ID, Sum(FY) from A Group by ID Order by ID 如果支持嵌套可以写成: Select * from (Select ID, Sum(FY) from A Group by ID) Order by ID
Select ID, Sum(FY) from A Group by ID Order by ID 如果支持嵌套可以写成: Select * from (Select ID, Sum(FY) from A Group by ID) Order by ID
秋 秋之叶 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #11 如果要更新的话,jqw 的方法就行。但Paradox好象不支持嵌套.
秋 秋之叶 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-26 #12 如果是用来汇总的话,不如另建一个汇总表。原来的明细资料也可以保留以备后用。
天 天真 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-27 #13 用JQW的方法在SQLSERVER 2000中不支持!能否不用新表就更新呢?
J jqw Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-27 #14 多走几步: create table tmp as select ID,SUM(FY) FROM A GROUP BY ID; delete from a; insert into a (select * from tmp); drop table tmp; 兄弟,再试试
多走几步: create table tmp as select ID,SUM(FY) FROM A GROUP BY ID; delete from a; insert into a (select * from tmp); drop table tmp; 兄弟,再试试
天 天真 Unregistered / Unconfirmed GUEST, unregistred user! 2001-12-27 #15 看来只好如此了,我只是想知道更好的办法!JQW你是哪 儿人?