我的代码如下:
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();
}
我从CustomerPayment
表中获取此记录。在此表格中,有一个type
字段,此类型字段可以包含两个值bank
和cash
代表:
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
我想要的是将BANKs金额和现金金额加起来并将它们放入数据表中。
我该怎么做?
答案 0 :(得分:0)
SELECT type ,SUM(amount) FROM CustomerPayment GROUP BY type
会回复你:
AMOUNT TYPE
BANK 370.75
CASH 250.25