表结构如下
id target_id score fromdate todate
1 111 90.1 2008-04-01 2008-04-30
2 121 30.1 2008-04-01 2008-04-30
3 312 23.3 2008-04-01 2008-04-30
4 111 83.2 2008-03-01 2008-03-31
5 312 123.2 2008-03-01 2008-03-31
6 121 122.1 2008-03-01 2008-03-31
7 111 123 2008-02-01 2008-02-29
8 111 123 2008-01-01 2008-01-31
9 121 321 2008-01-01 2008-01-31给 一个起止时间 查到 这个起止时间内 所有target 的 分数 和 每taget 从给定时间 到本年度1月 所有score现在我的方法是 写一个sql 能查出 给定起止时间的数据 比如给定时间是 2008-04-01 2008-04-30 程序生成
2008-03-01 2008-03-31 ,2008-02-01 2008-02-29 ,2008-01-01 2008-01-31 3个起止时间 再调用sql查询
根据 target_id 把相同的target 数据 放在一块 但是这样做的效率很差 谁有什么好的解决方法 给点思路,
ORZ 摆过。。
id target_id score fromdate todate
1 111 90.1 2008-04-01 2008-04-30
2 121 30.1 2008-04-01 2008-04-30
3 312 23.3 2008-04-01 2008-04-30
4 111 83.2 2008-03-01 2008-03-31
5 312 123.2 2008-03-01 2008-03-31
6 121 122.1 2008-03-01 2008-03-31
7 111 123 2008-02-01 2008-02-29
8 111 123 2008-01-01 2008-01-31
9 121 321 2008-01-01 2008-01-31给 一个起止时间 查到 这个起止时间内 所有target 的 分数 和 每taget 从给定时间 到本年度1月 所有score现在我的方法是 写一个sql 能查出 给定起止时间的数据 比如给定时间是 2008-04-01 2008-04-30 程序生成
2008-03-01 2008-03-31 ,2008-02-01 2008-02-29 ,2008-01-01 2008-01-31 3个起止时间 再调用sql查询
根据 target_id 把相同的target 数据 放在一块 但是这样做的效率很差 谁有什么好的解决方法 给点思路,
ORZ 摆过。。
select * from tt
where fromdate<=:datetime and fromdate>=trunc(:datetime,'yyyy')
order by target_id,fromdate
这样不行吗
target_id 2008-04-01 2008-03-01 2008-02-01 2008-01-01
111 90.1 83.2 123 123
121 30.1 122.1 null 321
312 312 123.2 null null不知道能不能用sql 写出来 我现在用程序 辅助的 比较慢