数据表如下:
ID | 时间 | 字段1 | 字段2 | 字段3 |
1 | 2006-11-2 1:10:00 | 001 | 60 | 30 |
2 | 2006-11-2 1:30:00 | 001 | 50 | 20 |
3 | 2006-11-2 1:10:00 | 002 | 50 | 10 |
4 | 2006-11-2 1:30:00 | 002 | 43 | 7 |
5 | 2006-11-2 2:15:00 | 001 | 80 | 10 |
6 | 2006-11-2 2:15:00 | 002 | 75 | 5 |
... | ... | ... | ... | |
23 | 2006-11-2 23:00:00 | 001 | 40 | 10 |
数据表描述:
1.字段1只可能是001和002,且每一时段字段1的数据为字段2和字段3的数据之和。
即 时间=2006-11-2 1:00:00时,001的数据为60+30,002的数据为50+10
2.每一时段002的数据来之001的字段2的数据。
即 时间=2006-11-2 1:00:00时,001的数据(50+10)=该时刻002的字段2的数据 60
报表如下:
时间段 | 字段2 | 字段3 | 比率 |
01:00:00-01:59:59 | 60 | 10 | 67/160 |
02:00:00-02:59:59 | 50 | 7 | |
... |
问题描述:
1.以1小时为间隔统计一天中001的字段2和002的字段3
2.某一个小时内,比率=(001的字段3+002的字段3)/001的字段2+001的字段3
即2006-11-2 1点这个小时内的比率=((30+20)+(10+7))/(60+50+30+20)
SQL语句:
![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
欢迎感兴趣的朋友一起讨论!