首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

高分求解,求思路,该怎么处理

2013-02-25 
高分求解,求思路需求描述:统计公司一年的财务开销情况。大概是这样的。页面上大概要求如下月份一月二月三月

高分求解,求思路
需求描述:
   统计公司一年的财务开销情况。大概是这样的。页面上大概要求如下
  月份  一月  二月   三月  四月......全年度
  收入  100    --    --    200 ....   300
  支出   --    --    200   50....     250
  合计  +100   --   -200   +150....   +50
页面大概就是这样的。数据如下:
id,  月份(时间),  金额,   类型(收/入)  。。。。其余字段不关注 数据库表中数据部分如下:
1    1            100       收入
2    3            200       支出
3    4            200       收入
4    4            50        支出


就是这么多了 ,然后问几个问题:
  第一:要达到我上面页面的展示效果,请问这样设计数据库是否合理?不合理怎么设计!
  第二:按照上面数据库的设计方式,请问sql语句该怎么写?是不是分组求和再排序?
  第三:(重点)现在假如数据已经由sql语句处理好了那么我的service层应该怎么来做这个业务逻辑数据呢
        既要分月算支出,收入,合计等还要当数据库中不存在该月的数据(如二月)时,页面也要默认的显       
        示出来--
谢谢各位朋友。感激不尽!学习了!
    


from
(select AmountType, case when amount = 0 or amount is null then '-' else amount end money
from T where AmountType in ('收入', '支出') and month=1) a
left join
(select AmountType , case when amount = 0 or amount is null then '-' else amount end money
from T b where AmountType in ('收入', '支出') and month=2)b
on a.AmountType = b.AmountType
left join
(select AmountType , case when amount = 0 or amount is null then '-' else amount end money
from T b where AmountType in ('收入', '支出') and month=3)c
on a.AmountType = c.AmountType

********结果*********
类型一月份二月份三月份
支出300-200
收入100--

热点排行