zoukankan      html  css  js  c++  java
  • SQL游标插入临时表

    创建临时表然后里面查询!!

    select convert(varchar(40),'总计') as data_category11,* into #temp01 
    from openquery(database,'select line,sum(total_times) as total_times from table
    where to_char(inserver_time-1,''yyyy'')=2019 group by line order by line')
    
    insert into #temp01 
    select convert(varchar(40),'卡总计') as data_category,* 
    from openquery(database,'select line_no,sum(total_times) as total_times from table
    where to_char(inserver_time-1,''yyyy'')=2019 and card_type=1 group by line_no order by line_no')
    
    insert into #temp01 
    select convert(varchar(40),'卡总计') as data_category,* 
    from openquery(database,'select line_no,sum(total_times) as total_times from table
    where to_char(inserver_time-1,''yyyy'')=2019 and card_type=1 group by line_no order by line_no')
    
    
    select a.*,b.line_name into #temp_f from #temp01 a,gj.dbo.oo b where a.line_no=b.line_no
    
    drop table #temp01
    
    
    declare @line_name varchar(40)
    set @line_name='%uuu%'
    
    select line_no,line_name,sum(客流) as '客流',sum(总计) as '卡总计',
    sum(卡总计) as '卡总计' from
    (
    select line_no,line_name,case data_o when '总计' then total_times else 0 end as '客流', 
    case data_category when '卡总计' then total_times else 0 end as '卡总计',
    case data_category when '卡总计' then total_times else 0 end as '卡总计'
    from #temp_f where line_name like @line_name
    )a group by line_no,line_name order by line_no,line_name
    
    
    
    drop table #temp_f

    可怕自己2年没有写博客了,可怕

  • 相关阅读:
    运算符重载
    vmware 下 ubuntu 不能全屏显示 的解决方法
    最优化
    常见算法(logistic回归,随机森林,GBDT和xgboost)
    转:CRF++词性标注
    条件随机场(CRF)理论及应用
    转:RNN(Recurrent Neural Networks)
    RNN(Recurrent Neural Networks)公式推导和实现
    ML、DL相关资源
    机器学习(周志华西瓜书) 参考答案 总目录
  • 原文地址:https://www.cnblogs.com/springcloud/p/15064113.html
Copyright © 2011-2022 走看看