求助表结构设计问题!

cysh 2004-12-18 03:08:46
我现在做一个自来水管理系统,用户的用水量是本月水表上的用水量减去该用户上月的用水量,根据用水量计算用户的费用。现在应该怎么设计表结构来存放每个月用户的数据?需要几张表?请各位给小弟指点!
...全文
149 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
smalldeer 2004-12-21
  • 打赏
  • 举报
回复
用户,日期,上月度数,本月度数

本月度数又是下个月的上月度数。


cysh 2004-12-21
  • 打赏
  • 举报
回复
还有别的方案没有?
lanbaibai 2004-12-18
  • 打赏
  • 举报
回复
就是象马克的
yingqing 2004-12-18
  • 打赏
  • 举报
回复
哈哈,馬可的我同意.
didoleo 2004-12-18
  • 打赏
  • 举报
回复
--同意马克老大的

create table water
(
userid varchar(4) null,
watertime varchar(10) null,
watervol numeric(14,2) null
)

insert into water
select '0001','2004-10-05',100 union all
select '0001','2004-11-05',150 union all
select '0001','2004-12-05',220 union all
select '0002','2004-10-05',100 union all
select '0002','2004-11-05',110 union all
select '0002','2004-12-05',200


select userid,watertime,本月应交 from (
select c.userid,d.watertime,c.watervol as 本月应交 from water c join (select userid,min(watertime) as watertime from water group by userid) d
on c.userid=d.userid and c.watertime=d.watertime
union all
select b.userid,b.watertime,(b.watervol-a.watervol) as benyue from water b,water a
where b.userid=a.userid and datediff(m,b.watertime,a.watertime)=-1
) a
order by watertime,userid
----------------------------------------
userid watertime 本月应交
0001 2004-10-05 100.00
0002 2004-10-05 100.00
0001 2004-11-05 50.00
0002 2004-11-05 10.00
0001 2004-12-05 70.00
0002 2004-12-05 90.00
631799 2004-12-18
  • 打赏
  • 举报
回复
up有分吗?
631799 2004-12-18
  • 打赏
  • 举报
回复
up.
lilu207 2004-12-18
  • 打赏
  • 举报
回复
如果不好查询来确定费用feiyong表中“该月用水度数”那就在mingxi(用户,检查日期,水表度数)表中增加一个字段“上月水表度数”,将上月个检查到的水表度数放到这个月来,虽然增加了冗余,可方便了很多。
lilu207 2004-12-18
  • 打赏
  • 举报
回复
方案不具体。试试一个明细表(mingxi),一个费用表吧(feiyong)。
明细表保存每个月检测的水表度数,时间,用户名,如楼上那样。
mingxi(用户,检查日期,水表度数)
feiyong(用户,某年某月,该月用水度数,每单位水价钱,该月费用)
feiyong表中的数据根据mingxi表获得,
txlicenhe 2004-12-18
  • 打赏
  • 举报
回复
用户,日期, 水表度数。
张三 20041130 100
李四 20041130 123
张三 20041231 200
李四 20041231 245



27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧