-1

I have below code:

this.session = HibernateUtil.getSessionFactory().getCurrentSession();
List<CustomerPayment> paymentList = null;
try {
  org.hibernate.Transaction tx = session.beginTransaction();
  Query q = session.createQuery(
    "from CustomerPayment where DATE like '%" + year + "'");
  paymentList = (List<CustomerPayment> ) q.list();
} catch (Exception e) {
  e.printStackTrace();
}

I take this records from CustomerPayment table. In this table, there is a type field and this type field can have two values bank and cash

for ex:

ID  CODE        DATE        AMOUNT  TYPE
1   CK-00004    11/14/2013  100.5   BANK
3   CK-00004    09/17/2013  250.75  BANK
4   CK-00004    08/20/2013  250.25  CASH

What I want is that to sum BANKs amount and CASH amount and put them into the datatable.

How can I do that?

4

1 回答 1

0
SELECT type ,SUM(amount) FROM CustomerPayment GROUP BY type

会回报你:

  AMOUNT     TYPE
  BANK       370.75
  CASH       250.25
于 2013-04-29T13:22:43.920 回答