2 ccl524 ccl524 于 2015.07.27 13:40 提问

请问在Dao方法中怎样求写一个多个和的方法

我这有个DAO方法,把查询语句中的那个都查出来:
public int getOrderCount(Date beginTime,Date endTime){
StringBuilder sql=new StringBuilder();
sql.append("SELECT SUM(C) AS cc,SUM(A) AS amount, round(SUM(A)/SUM(C), 2) AS avgPrice FROM (");
sql.append("SELECT COUNT(O.ID) AS C, SUM(o.amount + o.freight - o.discount) AS A FROM HOMEVV_ORDER O ");
sql.append("WHERE O.SOURCE = 'mobileOrder'");
sql.append("AND O.CREATETIME >= :beginTime ");
sql.append("AND O.CREATETIME <= :endTime ");
sql.append("UNION ALL");
sql.append("SELECT COUNT(O.ID) AS C, SUM(o.amount + o.freight - o.discount) AS A FROM HOMEVV_ORDER O ");
sql.append("INNER JOIN HOMEVV_MALL_STOREORDER SO ON (O.ID = SO.ORDER_ID)");
sql.append("WHERE O.SOURCE = 'mallstore' AND SO.CLIENTSOURCE IN ('iPhone', 'Android')");
sql.append("AND O.CREATETIME >= :beginTime ");
sql.append("AND O.CREATETIME <= :endTime)");
int count=getCountBySQLQuery(sql.toString(), new String[]{"beginTime","endTime"}, new Date[]{beginTime,endTime});
return count;
}怎样让它上面的值都在这个方法中查到。求教

3个回答

qq_17311469
qq_17311469   2015.07.27 13:46

用子查询

yuke198907
yuke198907   2015.07.27 13:52

得在getCountBySQLQuery这个方法里进行处理吧

sina_2831808769
sina_2831808769   Rxr 2015.07.27 22:12

把所需要的字段写加法式子就可以了 ,如select 字段1+字段2 from 表

Csdn user default icon
上传中...
上传图片
插入图片