我的情况与楼主类似。。。我的语句是
String sql = "select deptandplat_acronym,login_number,login_number_cn,action_type,sum(case when action_time>='"+last_day_start+"' and action_time<='"+last_day_end+"' then 1 else 0 end) last_day,"+
"sum(case when action_time>='"+avg_day_start+"' and action_time<='"+avg_day_end+"' then 1 else 0 end) avg_day,"+
"sum(case when action_time>='"+last_month_start+"' and action_time<='"+last_month_end+"' then 1 else 0 end) last_month,"+
"sum(case when action_time>='"+avg_month_start+"' and action_time<='"+avg_month_end+"' then 1 else 0 end) avg_month from original_profession_logs" + whereSql +
"group by deptandplat_acronym,login_number,action_type order by last_day desc,avg_day desc,last_month desc,avg_month desc";
表是分区表,按action_time分区,这个语句时间最大跨度是三个月,每次查询时间都要好几秒。
同求高手解决,如何优化。
楼上说的我明白,但是我的数据库已经分表了,大概一张表中有一两百万的数据,要是查询所有的话还可以,但是我的sql样本是这样的“select count(),count(),count(),sum(),sum() from tableName where {这里是一个日期判断,两个日期相差一百天或者三十天的公式} and '列名' like ‘%参数%’ and '列名'=‘参数’ group by 列名”
这样下来我的程序使用单纯的老套路就会变得非常慢,听说Java有一种检索机制,哪个大神明白,指点一二