Olá tenho uma tabela com dados mais ou menos dessa forma:
Item 5 $ 100,00
Item 1 $ 10,99
Item 3 $ 20,00
Item 4 $ 31,50
Item 3 $ 56,99
Item 1 $ 45,00
Item 4 $ 29,00
preciso recuperar atraves de um select a soma de cada item sem repiti-los
dessa forma:
Item 1 $ 55,99
Item 3 $ 76,99
Item 4 $ 60,50
Item 5 $ 100,00
então criei um metodo mas algo da errado:java.sql.SQLException: Column not found
Já verifiquei todos os nomes das colunas da tabela etc... esta tudo certo...mas não funciona...
Alguem sabe oque pode ser?? Grato!!
public LinkedList listaPercentual(int id, String dataInicial, String dataFinal) throws SQLException {
conn = retornaConn();
PreparedStatement stmt = null
LinkedList percentual = new LinkedList();
double totalGeral = totalGeralDespesas;
try {
stmt = conn.prepareStatement ("select CodOperacao, sum(Valor) from Tab_Extrato where Data between ? and ? and RecDesp = 1 and CodUsuario LIKE '%" + id + "%' group by CodOperacao");
stmt.setString(1, dataInicial);
stmt.setString(2, dataFinal);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
ExtratoBean extratoBean = new ExtratoBean();
extratoBean.setCodOperacao(rs.getInt("CodOperacao"));
extratoBean.setValor(rs.getDouble("Valor"));
percentual.add(extratoBean);
System.out.println("Operação n°: "+ extratoBean.getCodOperacao()+" Soma total Gasto $ "+extratoBean.getValor() );
}
rs.close();
}
catch (SQLException e) {
System.out.println("erro ao calcular " + e);
}
finally{
stmt.close();
conn.close();
}
return percentual;
}