0
Good evening. Please, I would like to ask you for help for the code below. It returns the total value (total values, saved in the database), but I need to return by month. I tried everything I knew, but I couldn’t solve the problem. I thank you in advance for the help.
EntityManagerFactory emf = Persistence.createEntityManagerFactory("belezaPU");
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<BigDecimal> criteriaQuery = builder.createQuery(BigDecimal.class);
Root<Venda> venda = criteriaQuery.from(Venda.class);
criteriaQuery.select(builder.sum(venda.<BigDecimal> get("precoTotal")));
TypedQuery<BigDecimal> query = em.createQuery(criteriaQuery);
BigDecimal totalVendas = query.getSingleResult();
System.out.println("A soma das vendas é: R$" + totalVendas);
What is the field name that contains the date of sale?
– Augusto Vasques
Hello Augusto, I’m sorry for the delay. The field is called schedule.
– Rubens Costa da Silva