sql server 循环算法
---------------------------------------------------
对账查询
select
a.oTime,a.Attribution,a.Operator,a.PackageName,olinecount,ISNULL(
newcount,0)
as newcount,a.PackagePrice,((olinecount + ISNULL( newcount,0))*
a.PackagePrice) as amount
from
(select COUNT(m.Mobile) olinecount,m.oTime,(nb.Province+nb.City) as
Attribution,
nb.Operator,m.Package as
PackageCode,d.PackageName,d.PackagePrice
from AndroidWS.dbo.AWS_StateAll m LEFT JOIN
AndroidWS.dbo.Aws_Package_Dict d
on m.package=d.PackageCode
LEFT JOIN
BussinessAnalyse.dbo.NumberSegment nb ON
SUBSTRING(m.Mobile,0,8)=nb.Segment
GROUP BY
m.oTime,nb.Province,nb.City,nb.Operator,m.Package,d.PackageName,d.PackagePrice)
a left join
(select COUNT(*) as newcount ,oline,package from (select
mobile,package,MIN(oTime) oline from
------------------------------------------------------
----------------------------------------------
查看明细
SELECT
Convert(varchar(4),YEAR(uu.t1))+'-'+Convert(varchar(2),MONTH(uu.t1)),
nb.Province + nb.City AS Attribution,
nb.Operator,
AS UserMobile,
FROM
SpNumber
Aws_Pakeage_Order_list_1
a.PaCode = b.PaCode AND a.CreateDate < b.CreateDate) AS uu
LEFT OUTER JOIN
GROUP BY
ORDER BY
----------------------------------------------------------------------
----------------------------------------------------------------------
视图
SELECT
FROM