0

这就是我所拥有的,它需要永远。我想不出另一种方法来做到这一点。我尝试了更慢的游标。有任何想法吗?谢谢你。

   declare @i int
    declare @customer_sk  int
    declare @numrows int
    declare @iprotable TABLE (idx int Primary Key IDENTITY(1,1),customer_sk int)
    INSERT @iprotable
    select distinct ipro.Customer_SK from IproProfile ipro inner join vwUsageLast60Days usage on usage.Customer_SK =ipro.Customer_SK 

    SET @i = 1
    SET @numrows = (SELECT COUNT(*) FROM @iprotable)
    IF @numrows > 0
        WHILE (@i <= (SELECT MAX(idx) FROM @iprotable))
        BEGIN
        SET @customer_sk = (SELECT customer_sk FROM @iprotable WHERE idx = @i)
        update IproProfile set TopClassification=x.clas
    from
    (
    select top 1 website web, classification clas, COUNT(classification)cnt, customer_sk cust_sk
    from vwusagelast60days group by website, customer_sk, classification
    having Customer_SK=@customer_sk
    order by cnt desc
    )x
    where Customer_SK=x.cust_sk
        set @i=@i+1
        end
4

0 回答 0