sql语句计算一年里分别每个月的收入

2024年11月11日 00:58
有4个网友回答
网友(1):

问题是,你一条记录只卖一件商品?
如果时的话: 每年每个月

select datepart(year,date)*100+datepart(month,date) YEARMONTH,count(*) SPSL,distinct(employee) from shopp
group by employee

如果表中shopp记录的是商品数量: 每年每个月

select datepart(year,date)*100+datepart(month,date) YEARMONTH,sum(shopp) SPSL,distinct(employee) from shopp
group by employee

网友(2):

select employee,sum(shopp) as 商品数,CONVERT (char(6), date ,112) as 时间
from shopp
group by employee,时间

select employee,sum(shopp) as 商品数,CONVERT (char(6), date ,112) as 时间
from shopp
group by employee,时间
having sum(shopp) >3

网友(3):

建议你行列转换,把列换成商品,员工和时间(1-12月)共14列来做,至于怎么行列转换,去网上一搜一堆,具体不写了

网友(4):

update
配件
set
套数
=(
select
round(min(a))
from
((select
零件1/1
as
a
from
配件)
union(select
零件2/2
as
a
from
配件)
union
(select
零件3/3
as
a
from
配件))
);