zoukankan      html  css  js  c++  java
  • 几个sql小知识

    一、查询效率分析语句
    /*
    set statistics io on;
    set statistics time on;
    */
    
    


     

    二、 查出重复数据

        select [GUID] from @Tab 
       where [GUID] in (select [GUID] from @Tab group by [GUID] having count([GUID])>1)
       order by [GUID]
    
     
    
    


     

    三、一个常用的想不来的语句且已被遗忘

     
    UPDATE a SET a.SaleZQ = b.OrganizationName
    FROM @WaitCheckImei a,EmoAsp.dbo.TB_ASP_Organization b,EmoAsp.dbo.TB_ASP_RetailStore c,EmoAsp.dbo.TB_ASP_Organization d
    WHERE  LEFT(d.OrganizationCode, 12) = b.OrganizationCode AND c.RetailStoreID = a.RetailStoreID
    


    四、when case的 嵌套

    select A.Oid,A.Nick as Buyer,A.Content,A.Result,@SellerNick as SellerNick,A.AddTime ,case b.Result
                                                                                                                 when 'good'        then '好评'
                                                                                                                 when 'bad'         then '差评'
                                                                                                                 when 'neutral'     then '中评'
                                                                                                                                    else '未审核'
                                                                                                                  end as Result
                                                                                                               ,case
                                                                                                               when b.oid is null or b.SellerNick is null then '未审核'
                                                                                                                                                    else '审核'
                                                                                                          end as IsRate
                            from
    
    


     

    五、高效分页的语句(2005以上版本)

      select *
    from
    (
    select row_number() over(order by guid) as RowNum, TableName.*
    from TableName) t
    where
    t.RowNum between 1120000 and 1120022
    
    


    六、设置测试表

    create Table 
    		T_Product
    		(Product_ID int
    		,Product_Name nvarchar(50))
    
    declare  @Product_ID int
    declare @Product_Name nvarchar(50)
    set @Product_ID=1
    set @Product_Name=''
    while @product_ID<30000
    begin
    	set @Product_ID=@Product_ID+1
    	set @Product_Name=('win'+cast(@Product_ID as nvarchar(10)))
    	insert into T_Product
    				(Product_ID
    				,Product_Name)
    			select @Product_ID,@Product_Name
    end

    把一个数据库里面的表的数据复制到另一个数据库相同的表里面

    insert into DB..abc select * from abc --其中abc为当前数据库的表




     

  • 相关阅读:
    对于HTML页面中CSS, JS, HTML的加载与执行过程的简单分析
    JavaScript中call,apply,bind方法的总结
    彻底理解js中this的指向,不必硬背
    cookie
    Cookie深度解析
    cookie和localstorage
    单页面应用和多页面应用
    can't access lexical declaration `a' before initialization
    http协议
    10、Javascript——数据类型(转载)
  • 原文地址:https://www.cnblogs.com/lzhp/p/2680765.html
Copyright © 2011-2022 走看看