选择哪一个选择 [英] Which of these Select to choose

查看:124
本文介绍了选择哪一个选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我目前加入的项目有以下选择

Hi,

I've currently joined a project that has the following select

SELECT TOP 1
     A.X
    ,A.Y
FROM
    (      
    SELECT 
        T.ENTITY_NAME   AS X
        ,T.SP_Y         AS Y
    FROM   
        dbo.TABLE       AS T
    WHERE  
         T.SP_Y      = @p_Y
     AND T.SP_EAT_ID = 16
    UNION ALL
    SELECT 
        T.ENTITY_NAME   AS X
        ,T.SP_Y         AS Y
    FROM   
        dbo.TABLE       AS T
    WHERE  
         T.SP_Y      = @p_Y
     AND T.SP_EAT_ID = 15
    ) AS A
) AS CN    ON CN.Y = H.Y





遗憾的是我无法提供有关数据的更多详细信息,但从提供的内容来看,你们有多少人说它可能与此不同:



Unfortunately I can't give more details about the data, but from what was provided, how much would you guys say it could differ from this:

SELECT TOP 1
    T.ENTITY_NAME   AS X
    ,T.SP_Y         AS Y
FROM   
    dbo.TABLE       AS T
WHERE  
     T.SP_Y      = @p_Y
 AND T.SP_EAT_ID in (15, 16)
ORDER BY
    T.SP_EAT_ID desc

推荐答案

由于此问题没有更多评论,没有提供解决方案。我和大学以及同事一起研究了这个问题,我们提出了以下解决方案:



使用



Since there were no more comments to this question and no solutions were provided. I've looked into this with both university and work colleagues and we came up with the following solution:

Use

SELECT TOP 1
    T.ENTITY_NAME   AS X
    ,T.SP_Y         AS Y
FROM   
    dbo.TABLE       AS T
WHERE  
     T.SP_Y      = @p_Y
 AND T.SP_EAT_ID in (15, 16)
ORDER BY
    T.SP_EAT_ID desc





这是所选择的一个,因为它更容易阅读并获得与第一个选择类似的性能。

有关比较的更多细节。请在2月19日阅读NeverJustHere的评论。



问候



This was the chosen one due to be easier to read and achieving a similar performance to the first select.
For more details on the comparison. Please read the comment of "NeverJustHere" at 19-Feb-14.

Regards


这篇关于选择哪一个选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆