当前位置: 代码迷 >> Sql Server >> 高手一个分类显示的存储过程
  详细解决方案

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

热度:18   发布时间:2016-04-27 17:47:36.0
请教各位高手一个分类显示的存储过程?
在一个数据表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 [email protected] and IpId=1)*100.00

(select count(1) from CubeViewLogs where [email protected]), 15,2))+ '% ' as 新客户,
ltrim(str((select count(1) from CubeViewLogs where [email protected] and IpId <> 1)*100.00

(select count(1) from CubeViewLogs where [email protected]), 15,2))+ '% ' as 老客户

[email protected]
  相关解决方案