关闭

企业数据统计分析工作

672人阅读 评论(0) 收藏 举报

企业数据统计分析工作


declare @tab1 table(ID int,
                    单号 varchar(20),
                    提货日期 datetime,
                    实发数量 decimal(8,1),
                    累计 decimal(8,1))
declare @ID int
declare @提货日期 varchar(20)
declare @实发数量 decimal(8,1)
declare @累计 decimal(8,1)

set @累计=0
declare Num_Cursor CURSOR FOR
 select * from @tab

open Num_Cursor
fetch next from Num_Cursor into @ID,@单号,@提货日期,@实发数量
wile @@FETCH_STATUS=0
begin
 set @累计=@累计+@实发数量
 insert @tab1
 values(@ID,@单号,@提货日期,@实发数量,@累计)
 fetch next from Num_Cursor into @ID,@单号,@提货日期
end

close Num_Cursor

deallocate Num_Cursr

 

 


declare Num_Cursor CURSOR FOR
select * from @tab

open Num_Cursor
fetch next from Num_Cursor into @ID,@单号,@提货日期,@实发数量
while @@FETCH_STATUS=0
begin
 set @累计=@累计+@实发数量
 insert @tab1
 values (@ID,@单号,@提货日期,@实发数量,@累计)
 fetch next from Num_Cursor into @ID,@单号,@提货日期,@实发数量
end

close Num_Cursor
deallocate Num_Cursor

select * from @tab1

 


identity identity

 

select 日期,店铺名,销售量
from DezaiCn_Sale
group by 日期,店铺名,销售量
order by 店铺名

 


select 店铺名,SUM(销售量) as 总销售量
from DezaiCn_Sale
where (店铺名='A') and (日期 between '2008-1-1' and '2008-9-1')
group by 店铺名

 


select SUM(销售量) as 销售总量,日期
from DezaiCn_Sale
where (日期='2008-3-1')
group by 日期

 

 

Create procedure DezaiCnTestSale_SalerCompareSaleByDate /*代理销售产品比较*/
@ProductIDArray varchar(1000),/*产品ID组*/
@begindate datetime,/*比较开始日期*/
@endDate datetime,/*比较结束时间*/
@shop varchar(20)/*店铺名*/

as
 declare @sql varchar(8000)
 set @sql='select 产品ID'

 select @sql=@sql+',max(case Convert(varchar(10),日期,120) when ''''+Convert(varchar(10),日期,120)+'''' then 销售量 else 0 end)['+Convert(varchar(10),日期,120)+']'

from (select distinct 日期 from DezaiCn_Sale where 日期 between @begindate and @endDate) as a


set @sql=@sql+' from DezaiCn_Sale where 产品ID in ('+@ProductIDArray+') and 店铺名=''''+@shop+''''
group by 产品Id'

exec(@sql)
go

select name,sum(score) as ZCJ
 from stuscore
group by name
order by zcj

 

select distinct t1.name,t1.stuid,t2.allscore
from stuscore t1,
     (
      select stuid,sum(score) as allscore
       from stuscore
      group by stuid
      ) t2
where t1.stuid=t2.stuid
order by t2.allscore desc


select t1.stuid,t1.name,t1.subject,t1.score
 from stuscore t1,
      (
       select stuid,max(score) as maxscore
        from stuscore
        group by stuid
      ) t2
where t1.stuid=t2.stuid
      and t1.score=t2.maxscore

 


select distinct t1.stuid,t1.name,t2.avgscore
 from stuscore t1,
      (
       select stuid,avg(score) as avgscore
        from stuscore
        group by stuid
      ) t2
where t1.stuid=t2.stuid
     


select t1.stuid,t1.name,t1.subject,t2.maxscore
 from stuscore t1,
      (
       select subject,max(score) as maxscore
        from stuscore
       group by subject
      ) t2
where t1.subject=t2.subject
      and t1.score=t2.maxscore

 

select distinct t1.*
 from stuscore t1
 where t1.id in(
                select top 2 stuscore.id
                  from stuscore
                 where subject=t1.subject
                 order by score desc
                )
order by t1.subject

 

select stuid as 学号,
       name as 姓名,
       sum(case when subject='语文' then score else 0 end) as'语文',
       sum(case when subject='数学' then score else 0 end) as'数学',
       sum(case when subject='英语' then score else 0 end) as'英语',
       sum(score) as 总分,
       (sum(score)/count(*))as 平均分
 from  stuscore
 group by stuid,name
 order by 总分 desc


select subject,avg(score) as avgscore
 from stuscore
 group by subject


declare @tmp table(pm int,name varchar(50),score int,stuid int)
insert into @tmp
        select null,name,score,stuid
          from stuscore
         where subject='数学'
         order by  score desc
declare @id int
  set @id=0;
update @tmp set @id=@id+1,
                pm=@id
select * form @tmp where name='李四'

 

selecdt subject,
        (select count(*) from stuscore where score<60 and subject=t1.subject) as 不及格,
        (select count(*) from stuscore where score between 60 and 80 and subject=t1.subject) as 良,
        (select count(*) from stuscore where score>80 and subject=t1.subject) as 优秀
from stuscore t1
group subject

 

declare @s varchar(1000)
set @s=''
select @s=@s+','+name+'('+convert(varchar(10),score)+'分)'
 from sutuscore
 where subject='数学'
set @s=stuff(@s,1,1,'')
print'数学:'+@s

 


select a.Description,
       Record_Count=Count(b.ID),
       [Percent]=case
                    when Counts=0 then '0.00%'
                    else cast(cast(count(b.ID)*100./c.counts as decimal(10,2)) as varchar)+'%'
                  end
from(
     select sid=1,a=Null,b=30,Description='<30'
     union all
     select sid=2,a=30,b=60,Description='>30 and <60'
     union all
     select sid=3,a=60,b=75,Description='>=60 and <75
    ) a Left join @t b
             on(b.col<a.b or a.b is null)
                and(b.col>=a.a or a.a is null)
            cross join(select counts=count(*) from @t)c
group by a.Description,a.sid,c.counts
order by a.sid

 


with Form2 do
begin
  for i:=0 to ComponentCount-1 do
     if(Components[i] is TCustomEdit) then
        TCustomEdit(Components[i]).text:=IntToStr(i);
end

 


procedure TForm2.btnClick(Sender:TObject);
var
  sformat:string;
  i,iSum:Integer;
  ObjArray:array of Integer;
  arrayCount:Integer;
  temp:string;
begin
  arrayCount:=0;
  temp:='';
  iSum:=0;

  sformat:=Trim(edt1.Text);
  for i:=1 to Length(sformat) do
  begin
    if sformat[i] in ['0'..'9'] then
    begin
       temp:=temp+sformat[i];
       if(i=Length(sformat)) then
       begin
         Inc(arrayCount);

         SetLength(ObjArray,arrayCount);
         ObjArray[arrayCount-1]:=StrToInt(temp);
       end;
    end else
    begin
      if temp<>'' then
      begin
         Inc(arrayCount);
         SetLength(ObjArray,arrayCount);
         ObjArray[arrayCount-1]:=StrToInt(temp);
         temp:='';
      end;
    end;
  end;
 
  for i:=0 to High(ObjArray) do
  begin
    edt2.text:=edt2.text+'+'+IntToStr(ObjArray[i]);
    Inc(iSum,ObjArray[i]);
  end;

  edt2.text:=RightStr(edt2.Text,(Lenght(edt2.text)-1))+'='+IntToStr(iSum);
end;

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:55487次
    • 积分:1423
    • 等级:
    • 排名:千里之外
    • 原创:73篇
    • 转载:5篇
    • 译文:0篇
    • 评论:1条
    最新评论
  • FastReport的使用

    highfiresun: 楼主威武,写的太好了。我有个问题还想请教:我怎么调用ExportTo导出各种文件?另外,能否加我Q探...