首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

高手一个分类显示的存储过程

2012-01-23 
请教各位高手一个分类显示的存储过程?在一个数据表A中有,BusinessID,CustomerID,CompanyID,Year,Month,Day

请教各位高手一个分类显示的存储过程?
在一个数据表A中有,BusinessID,CustomerID,CompanyID,Year,Month,Day等字段。CustomerID表示客户。如果是新客户第一访问则CumstomerID为1,如果不是新客户没次访问CustomerID加1,现在要统计这张表中的新、老客户各占的百分比,并将统计的百分比显示。请问高手们该如何实现这一存储过程。

[解决办法]
select
ltrim(str((select count(1) from A where id=1)*100.00
/
(select count(1) from A), 15,2))+ '% ' as 新,
ltrim(str((select count(1) from A where id <> 1)*100.00
/
(select count(1) from A), 15,2))+ '% ' as 老

[解决办法]
select
ltrim(str((select count(1) from CubeViewLogs where CutsomerID=@CustomerID and IpId=1)*100.00

(select count(1) from CubeViewLogs where CutsomerID=@CustomerID), 15,2))+ '% ' as 新客户,
ltrim(str((select count(1) from CubeViewLogs where CutsomerID=@CustomerID and IpId <> 1)*100.00

(select count(1) from CubeViewLogs where CutsomerID=@CustomerID), 15,2))+ '% ' as 老客户

要对@CustomerID进行定义!

热点排行