mysql 收入_mysql 收支统计问题

#开支项目droptableifexistswl_spending_name;createtableifnotexistswl_spending_name(idint(10)unsignednotnullauto_incrementprimarykey,#IDnamevarchar(50)notnull,#名称typesmal...

#开支项目

drop table if exists wl_spending_name;

create table if not exists wl_spending_name(

id int(10) unsigned not null auto_increment primary key, #ID

name varchar(50) not null, #名称

type smallint(1) not null, #类别,收入还是开支,1收入,2开支

create_time datetime not null, #创建时间

state smallint(1) not null, #状态 1为正常 0为删除

operator varchar(50) not null #操作员

)engine myisam charset gbk;

#开支明细

drop table if exists wl_spending_detail;

create table if not exists wl_spending_detail(

id int(10) unsigned not null auto_increment primary key, #ID

name_id int(10) unsigned not null, #所属项目ID

name varchar(300) not null, #收支内容

money decimal(10,2) not null, #收支金额

type smallint(1) not null, #类别,1未结账 2已结账

state tinyint(1) not null, #状态 0删除 1正常

create_time datetime not null, #创建时间

modified_time datetime not null default '0000-00-00 00:00:00', #修改时间

operator varchar(50) not null #操作员

)engine myisam charset gbk;

表结构如上,我的问题是当天结账时计算出每个项目的开支。

效果如下

项目1 项目2 项目3 ……

计算出来的总金额 100.00 200.00 200.00 ……

现在我只有一种方案sql

select n.id,n.name,d.name,d.money,d.type from wl_spending_name as n left join wl_spending_detail as d on d.name_id=n.id limit 100

结果出来后然后在程序中计算。

有没有什么好的办法去解决呢。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值