Posted on 2007-05-28 15:31
change 阅读(425)
评论(0) 编辑 收藏
CREATE TABLE V_GIS_MONTH
(
ID VARCHAR2(255 BYTE) NOT NULL,
VISITTIME DATE DEFAULT NULL,
GISNAME VARCHAR2(255 BYTE),
GISLEVEL VARCHAR2(255 BYTE),
PARENT VARCHAR2(255 BYTE),
VNUMBER NUMBER(19),
IPFROM VARCHAR2(255 BYTE),
IPLEVEL VARCHAR2(2 BYTE),
GISPATH VARCHAR2(1024 BYTE)
)
TABLESPACE USERS
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
LOGGING
NOCACHE
NOPARALLEL;
ALTER TABLE V_GIS_MONTH ADD (
PRIMARY KEY (ID)
USING INDEX
TABLESPACE USERS
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
));
select gisdays.ipfrom,gisdays.gisname,sum(gisdays.vnumber)AS count from V_Gis_Month gisdays where gisdays.GISPATH = '/sotrip_dest/destination_home/china/zhejiang/' and gisdays.iplevel='3' group by gisdays.ipfrom,gisdays.gisname ORDER BY count desc;
gis:表示目的地
在数据库里面这样的查询是可以的,但是用这样的语句在hibernate的DAO层
这样做:
String queryString = "select gisdays.ipfrom,sum(gisdays.vnumber) AS count from "+strtable+" gisdays where gisdays.iplevel='"+striplevel+"' "+strquery+" and to_char(gisdays.visittime,'YYYY-MM-DD') between '"+strfrom+"' and '"+strto+"' group by gisdays.ipfrom ORDER BY count desc";
Iterator iterator = this.getHibernateTemplate().find(queryString).iterator();
是不行的,会出现异常,报错。
改为:
String queryString = "select gisdays.ipfrom,sum(gisdays.vnumber) from "+strtable+" gisdays where gisdays.iplevel='"+striplevel+"' "+strquery+" and to_char(gisdays.visittime,'YYYY-MM-DD') between '"+strfrom+"' and '"+strto+"' group by gisdays.ipfrom ORDER BY sum(gisdays.vnumber) desc";
Iterator iterator = this.getHibernateTemplate().find(queryString).iterator();
while(iterator.hasNext())
{
Object[] pair = (Object[])iterator.next();
VGisMonth gismonth = new VGisMonth();
for(int i=0;i<pair.length;i++)
{
System.out.println("pair["+i+"]="+pair[i]);
}
}//这里iterator 所返回的是对象数组,它把取得的每一列都作为一个对象,然后返回一个对象数组的叠代器,然后我们就可以取出里面的每一列(对象)转换成相应的数据类型,(这里 strtable 是table所对应的实体的名字)
就可以了。应该是在里面不支持对 统计添加的列 的别名命名吧。呵呵:)