日期:2014-05-18  浏览次数:20338 次

请教各位高手一个分类显示的存储过程?
在一个数据表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进行定义!