0
CREATE PROCEDURE Dataloading
AS
BEGIN
    truncate table TABLE1

    insert TABLE1 (
        [Name],
        [Share]
    )
    select 
        [Name], 
        sum(Share)
    from TABLE2
    group by [Share]

END

输出:

texas     3000 
dallas    5000
ca        5000
sfo       7000
newyork   8000
G total  28000
alaska    4000
Total    24000

但是我最后需要进入阿拉斯加,并且beofre之前的一排必须是空的?

注意:我留空是因为我将此输出发送到 XL 表,并且我正在使用一些计算。但我是手动做的,是否需要对 SP 进行任何修改。

帮帮我!

4

1 回答 1

3

尝试这个

 select 
        [Name], 
        sum(Share)
    from TABLE2
    group by [Share]

order by case when name= 'alaska' then 1 else 0 end

编辑

insert...

select [name],summ from (
 select 
        [Name], 
        cast (sum(Share) as nvarchar(100)) as summ
    from TABLE2
    group by [Share]

union all select '',''
) a 
  order by case  name when  '' then 2  
 when  'alaska' then 3    
else 1 end
于 2013-09-10T15:59:48.720 回答