问题描述
我有一个名为Stock details的表,其中包含诸如
的列日期/工厂1/工厂2/工厂3/总数/月总数/年总数.
{总计为factory1 + factory2 + factory3}
{month_total是从第一个月到该月的当前日期的库存详细信息}
{year_total是从1月1日到当前日期的库存详细信息}
所以这里的问题是我该如何编写查询来计算n年的月份总数
请帮忙!
谢谢☻☻☺☺☺
I''ve table called Stock details which has columns like
date/factory1/factory2/factory3/total/month_total/year_total.
{Total is factory1+factory2+factory3}
{month_total is stock details from the 1st month to the current date of that month}
{year_total is stock details from the 1st jan to the current date}
So the problem here is how do i write query to calculate year n month total
Please help!!
Thank you☻☻☺☺☺
推荐答案
select monthtotal+yeartotal_id as total from stockdetails
更新的解决方案:
updated solution:
select sum(total) as month_Total from stockdetails where day(date)<=day(Getdate()) and month(date)=month(getdate()) and year(Date)=year(getdate())
上面的查询将为我提供特定月份(从第一天到当前日期)的总计列的总和.
The above query will give me sum of total column for the particular month 1st to current date.
select sum(total) as year_total from stockdetails where day(date)<=day(Getdate()) and month(date)<=month(getdate()) and year(Date)=year(getdate())
如果您的表contians列具有月份总数和年份总数,则将为您提供总计年份
this will give you years total
select datepart(year,dt) yr, datepart(mm,dt) month, month_tot,year_tot
from users
where dt in (select max(dt) from Stock_details
group by datepart(year,dt),
datepart(mm,dt))
order by 1 asc,2 asc,3 asc
这篇关于汇总数据库中的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!