用sql 实现报表查询
现在有4张表,销售表、进货表、企业支出费用表、其他费用表,现在客户要求算出当月每天的利润,利润=销售额(销售表中)-进货成本(进货表)-支出费用(企业支出费用表)-其他费...
现在有4张表,销售表、进货表、企业支出费用表、其他费用表 ,现在客户要求算出当月每天的利润,
利润=销售额(销售表中)-进货成本(进货表)-支出费用(企业支出费用表)-其他费用(其他费用表),
要显示一个月中每天的利润,求写sql 语句。 展开
利润=销售额(销售表中)-进货成本(进货表)-支出费用(企业支出费用表)-其他费用(其他费用表),
要显示一个月中每天的利润,求写sql 语句。 展开
4个回答
2014-01-22
展开全部
select sales.a,sales.b - inbuy.b - cost1.b - cost2.b
from
(select date as a,sum(销售额) as b from 销售表 where date between 开始日期 and 结束日期 group by date ) as sales,
(select date as a,sum(进货额) as b from 进货表 where date between 开始日期 and 结束日期 group by date) as inbuy,
(select date as a,sum(支出额) as b from 企业支出费用表 where date between 开始日期 and 结束日期 group by date) as cost1,
(select date as a,sum(费用额) as b from 其他费用表 where date between 开始日期 and 结束日期 group by date) as cost2
where
sales.a = inbuy.a and
sales.a = cost1.a and
sales.a = cost2.a
from
(select date as a,sum(销售额) as b from 销售表 where date between 开始日期 and 结束日期 group by date ) as sales,
(select date as a,sum(进货额) as b from 进货表 where date between 开始日期 and 结束日期 group by date) as inbuy,
(select date as a,sum(支出额) as b from 企业支出费用表 where date between 开始日期 and 结束日期 group by date) as cost1,
(select date as a,sum(费用额) as b from 其他费用表 where date between 开始日期 and 结束日期 group by date) as cost2
where
sales.a = inbuy.a and
sales.a = cost1.a and
sales.a = cost2.a
展开全部
SELECT x.riqi,(x.xiaoshoue - j.chengben - z.feiyong - q.qita) AS lirun FROM xiaoshou X,jinhuo j,zhichu z,qita q WHERE x.riqi = j.riqi AND x.riqi = z.riqi AND x.riqi = q.riqi
追问
你的也可以实现,但是分只能给一个,不好意思啊
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
4张表,销售表、进货表、企业支出费用表、其他费用表 是怎么关联的?用哪个字段?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有字段怎么写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |