滥用聚合函数SUM()

时间:2017-10-28 17:03:20

标签: java sqlite

我想在Somme_versee列中插入Versement的SUM(表Versement_total中的列)。 这是我的代码的一部分:

statement.executeUpdate("INSERT INTO Versement ( Nom , Prenom, Date , Somme_versee,Prix_du_logement, Nom_du_projet) VALUES('" + nom.getText() +"','" +prenom.getText() +"','"  +date.getText() + "'," +  verse.getText() + ", " + "(SELECT Prix_du_logement FROM Client WHERE Nom='"+ nom.getText() +"' AND Prenom='"+ prenom.getText() + "')," + " (SELECT  Nom_du_projet  FROM Client WHERE Nom='" + nom.getText()+ "' AND Prenom='" +prenom.getText() + "'))");
statement.executeUpdate("UPDATE Versement SET Versement_total= SUM(Somme_versee) " );

执行时我收到此错误:misuse of aggregate function SUM()

1 个答案:

答案 0 :(得分:0)

你永远不应该在同一张桌子上这样做。当表获得更多记录时,它会变得更糟。但你似乎想要的是:

UPDATE Versement SET Versement_total = (SELECT SUM(Somme_versee) FROM Versement)