开发者

exclude from union by only one out field

开发者 https://www.devze.com 2022-12-20 04:40 出处:网络
SELECT A.ID_ListGroupParIzm, A.Name, 0 AS Point FROM CfgListGroupParIzm A, CfgIzmeritel B WHERE A.ID_TypeIzmerit = B.ID_TypeIzmerit
SELECT A.ID_ListGroupParIzm, A.Name, 0 AS Point  
FROM CfgListGroupParIzm A, CfgIzmeritel B 
WHERE A.ID_TypeIzmerit = B.ID_TypeIzmerit   
AND B.ID_Izmerit=@ID_Izmerit AND A.Fo开发者_运维技巧rRun=0 

UNION  

SELECT A.ID_ListGroupParIzm, (C.Name + ' ' + A.Name) AS Name, C.ID_IzmerPoint AS Point  
FROM CfgListGroupParIzm A, CfgIzmeritel B, CfgIzmerPoint C  
WHERE A.ID_TypeIzmerit = B.ID_TypeIzmerit  
AND B.ID_Izmerit=@ID_Izmerit AND A.ForRun=1  
AND C.ID_Izmerit=@ID_Izmerit

EXCEPT

SELECT ID_Group --, '' AS Name, 0 AS Point here I don't know their names and a Point :(
FROM TbUserGroup
WHERE ID_Izmerit=@ID_Izmerit AND
ID_User=@ID_User AND ID_Point=@ID_Point

there was idea - using Except but I need to know all fields for it (I know only one) , so I need exclude from this union nodes with ID_Group under except :-/ I'm thinking about combine it.

How to make it ? or some ideas ... or advices ...


You could try something like

SELECT  *
FROM    (
            SELECT  A.ID_ListGroupParIzm, 
                    A.Name, 
                    0 AS Point   
            FROM    CfgListGroupParIzm A, 
                    CfgIzmeritel B  
            WHERE   A.ID_TypeIzmerit = B.ID_TypeIzmerit    
            AND     B.ID_Izmerit=@ID_Izmerit 
            AND     A.ForRun=0  
            UNION   
            SELECT  A.ID_ListGroupParIzm, 
                    (C.Name + ' ' + A.Name) AS Name, 
                    C.ID_IzmerPoint AS Point   
            FROM    CfgListGroupParIzm A, 
                    CfgIzmeritel B, 
                    CfgIzmerPoint C   
            WHERE   A.ID_TypeIzmerit = B.ID_TypeIzmerit   
            AND     B.ID_Izmerit=@ID_Izmerit 
            AND     A.ForRun=1   
            AND     C.ID_Izmerit=@ID_Izmerit 
        ) sub 
WHERE   sub.ID_ListGroupParIzm NOT IN 
                (
                    SELECT  ID_Group 
                    FROM    TbUserGroup 
                    WHERE   ID_Izmerit=@ID_Izmerit 
                    AND     ID_User=@ID_User 
                    AND     ID_Point=@ID_Point 
                )
0

精彩评论

暂无评论...
验证码 换一张
取 消