zoukankan      html  css  js  c++  java
  • sql2008 join语句另一种用法,减少运行速度

    CREATE PROCEDURE [dbo].[sp_get_user_configs]
    @system_id int,
    @config_table_version int,
    @specified_uids nvarchar(max)
    AS
    BEGIN

    if(@system_id < 1)
    return
    if(@config_table_version =0)
    set @config_table_version = null

    -- 取得 system_type
    declare @system_type int
    select @system_type=system_type from t_system where system_id = @system_id

    ;with _x as (
    SELECT user_id
    ,[config_item_id]
    ,[config_item_value]
    ,[config_deadline]
    ,[config_item_title]
    ,[config_item_name]
    ,[config_item_type]
    ,[config_table_id]
    ,[system_type]
    ,[config_table_version]
    ,0 as [type]
    ,'用户私有' as [type_name]
    ,config_item_parent_id
    FROM [v_user_config]
    right join (select item from f_str_split(@specified_uids)) as b
    on b.item = user_id
    where system_type=@system_type and config_table_version=ISNULL(@config_table_version,config_table_version)
    union all
    SELECT [user_id]
    ,[config_item_id]
    ,[config_item_value]
    ,[config_deadline]
    ,[config_item_title]
    ,[config_item_name]
    ,[config_item_type]
    ,[config_table_id]
    ,[system_type]
    ,[config_table_version]
    ,[role_id] as [type]
    ,[role_name] as [type_name]
    ,config_item_parent_id
    FROM [v_role_config]
    right join (select item from f_str_split(@specified_uids)) as c
    on c.item = user_id
    where system_type=@system_type and config_table_version=ISNULL(@config_table_version,config_table_version)
    )
    select
    [user_id],
    [config_item_id],
    [type],
    [type_name],
    [config_item_title],
    [config_item_name],
    [config_item_value],
    [config_item_type],
    [config_deadline],
    [config_table_id],
    [system_type],
    [config_table_version],
    config_item_parent_id
    from _x
    order by user_id desc

    END

  • 相关阅读:
    畅销书排行榜
    阿里云大数据产品体系
    天然气收费管理系统的研究与实现随笔
    Web端实现RTC视频特效的解决方案
    从0搭建在线聊天室,只需4步!
    技术干货 | JavaScript 之事件循环(Event Loop)
    C++20 四大特性之一:Module 特性详解
    Android Flutter 多实例实践
    网易云信线上万人连麦技术大揭秘
    Python + Pytest 自动化框架的用例依赖实操
  • 原文地址:https://www.cnblogs.com/babyfacer/p/2547829.html
Copyright © 2011-2022 走看看