日期:2014-05-20 浏览次数:20721 次
import java.util.List; import javax.sql.DataSource; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.support.JdbcDaoSupport; /** * 作者@:chen boning * * @说明:自定义 */ public class EhomeJoyDAO { JdbcTemplate jdbcTemplate; /** * 销售统计 * * @param enterpriselogname * @return */ public List getbusinessbuy(String enterpriselogname, String date) { String sql = "select t.goodsname,sum(t.sumprice) as sumprice from ehome_vjoy t where t.enterpriselogname='" + enterpriselogname + "' and to_char(t.lasttime,'yyyy-MM-dd') like '2008-" + date+"-%'group by t.goodsname"; List list = this.getJdbcTemplate().queryForList(sql); return list; } public JdbcTemplate getJdbcTemplate() { return jdbcTemplate; } public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } /** * 财务报表 * * @return */ public List getbusinessreport(String enterpriselogname, String date) { String sql = "select t.goodsname,sum(t.sumprice) as sumprice,t.enterprisename from ehome_vjoy t where t.enterpriselogname='" + enterpriselogname + "' and to_char(t.lasttime,'yyyy-MM-dd') like '2008-" + date+"-%'group by t.goodsname,t.enterprisename"; List list = this.getJdbcTemplate().queryForList(sql); return list; }
------解决方案--------------------
正在关注中,请稍候。。。。。
------解决方案--------------------
hql 是操作对象的,如果你这三个表没有关系,不能用union
用sql是正确的选择:
如果contest-id 是这三个表的主键,并且都是一一对应的:
表一有4个字段分别为contest-id title remester score
表二有三个字段分别为contest-id type id
表三有两个字段分别为contest-id sutudent-id
select contest-id ,title ,sum(case或者decode函数(oracle专用)(score >= 60,1,0) )合格人数,count(score ) 总数,sum(case或者decode函数(oracle专用)(type = 0,1,0) )类型为0的数,
sum(case或者decode函数(oracle专用)(type = 1,1,0) )类型为1的数,
sum(case或者decode函数(oracle专用)(type = 2,1,0) )类型为2的数
from 表1,表2,表三
where 表1.contest-id = 表2.contest-id = 表3.contest-id
group by contest-id ,title