要求:表a中有字段 物品名称,价格,销售数量,日期
sql语句,实现结果显示 第一周销售数量,第二周销售数量,或第一个月销售数量,第二个月销售数量
可以不显示其他内容。
sql语句,实现结果显示 第一周销售数量,第二周销售数量,或第一个月销售数量,第二个月销售数量
可以不显示其他内容。
解决方案 »
- MSSQL数据库表设计问题!
- 存储过程问题 ,在线等待
- 各位大哥,如何将字符串转换为数字?
- 怎么取某列值相同的记录集(排序)的最后一条记录
- 急。。如何使用变量执行选择数据库?
- 用VB语句或SQL语句如何知道系统已经安装了SQL SERVER 2000或更高版本。
- 新人提问,求前辈指点
- 用alter语句修改视图时(语法都正确),但可能有些列(或关联表)不存在所以导致有出错提示,最终更新不成功!现在怎样忽略这种提示并使得更
- 将A表的数据插入B表的同时, 还需要插入额外的两个字段, 该如何设置呢?
- 请问在SQL Server 2000如何建DTS包?
- update from 用法
- exec('create table '+'#tt varchar(20)')非常奇怪???
insert into table1 values(2,'2003-4-29',14588,2,1001)
insert into table1 values(3,'2005-5-12',125664,3,1003)
insert into table1 values(4,'2002-1-22',645555,5,1002)insert into table1 values(5,'2005-2-22',64457,1,1004)
insert into table1 values(6,'2005-8-22',64457,1,1004)
insert into table1 values(7,'2005-4-22',64457,1,1004)
insert into table1 values(8,'2005-12-22',64457,1,1004)
insert into table1 values(9,'2005-6-22',64457,2,1004)
insert into table1 values(10,'2005-9-22',64457,2,1004)
insert into table1 values(11,'2005-11-22',64457,4,1004)go
select tid, year(ttime)as years,month(ttime) as months,balance,yyt,person into table3 from table1
go
select *from table3
go
select t3.*, (t3.months1+t3.months2+t3.months3+t3.months4+t3.months5) as sumprice,
(t3.months1+t3.months2+t3.months3+t3.months4+t3.months5)/5 as avgprice
from(select years ,
sum( case t.months when 1 then balance else 0 end) as months1,sum(case t.months when 2 then balance else 0 end) as months2,
sum (case t. months when 3 then balance else 0 end )as months3,
sum (case t.months when 4 then balance else 0 end) as months4,
sum (case t.months when 5 then balance else 0 end) as months5
from table3 as t
group by t.years) as t3
balance 营业额,yyt是几号窗口,person是员工代号
from a
group by 物品名称,DATEPART(week,日期)--DATEPART(week,日期)返回本日期属于本年度的第几周,强烈建议lz看看下边这个
http://blog.joycode.com/ghj/archive/2003/11/11/6319.aspx