SQL: вложенный запрос с использованием синтаксиса «И НЕ СУЩЕСТВУЕТ»


0

Может быть, проблема заключается в том, что основной запрос не связан с не существует подзапроса. Попробуй:

создайте псевдоним для всей таблицы, а не в подзапросе, присоединитесь только к основному запросу «где» подзапроса

    SELECT        
    SS_0.memid
FROM
    SS SS_0
INNER JOIN
    SSUSED SSUSED_0 ON SS_0.ssid = SSUSED_0.ssid 
INNER JOIN
    MEMBERS MEMBERS_0 ON SS_0.memid = MEMBERS_0.memid 
INNER JOIN
    PRODUCTS PRODUCTS_0 ON SS_0.productid = PRODUCTS_0.productid 
INNER JOIN
    PRODUCTCATS PRODUCTCATS_0 ON PRODUCTS.productcatid = PRODUCTCATS.productcatid 
                AND NOT EXISTS (SELECT SS_1.memid
                                FROM SS AS SS_1  
                                INNER JOIN SSUSED AS SSUSED_1 ON SS_1.ssid = SSUSED_1.ssid 
                                INNER JOIN MEMBERS AS MEMBERS_1 ON SS_1.memid = MEMBERS_1.memid 
                                INNER JOIN PRODUCTS AS PRODUCTS_1 ON SS_1.productid = PRODUCTS_1.productid 
                                INNER JOIN PRODUCTCATS AS PRODUCTCATS_1 ON PRODUCTS_1.productcatid = PRODUCTCATS_1.productcatid
                                WHERE (SSUSED_1.usedate BETWEEN @rvStartWeek2 AND @rvEndWeek2) 
                                  AND (PRODUCTS_1.productcatid IN (27, 28, 29, 58, 77, 75, 30, 61, 31, 32, 47, 68)) 
                                  AND (MEMBERS_1.siteid = @rvSite)
                                  AND (SS_0.memid = SS_1.memid) -- Joint main Query and Subquery
                           )
WHERE        
    (SSUSED_0.usedate BETWEEN @rvStartWeek1 AND @rvEndWeek1) 
    AND (PRODUCTS_0.productcatid IN (27, 28, 29, 58, 77, 75, 30, 61, 31, 32, 47, 68)) 
    AND (MEMBERS_0.siteid = @rvSite)
SQL, SQL-сервер, SQL-сервер-2008, SSRS-2008,

sql,sql-server,sql-server-2008,ssrs-2008,

0

Ответов: 1


0

Может быть, проблема заключается в том, что основной запрос не связан с не существует подзапроса. Попробуй:

создайте псевдоним для всей таблицы, а не в подзапросе, присоединитесь только к основному запросу «где» подзапроса

    SELECT        
    SS_0.memid
FROM
    SS SS_0
INNER JOIN
    SSUSED SSUSED_0 ON SS_0.ssid = SSUSED_0.ssid 
INNER JOIN
    MEMBERS MEMBERS_0 ON SS_0.memid = MEMBERS_0.memid 
INNER JOIN
    PRODUCTS PRODUCTS_0 ON SS_0.productid = PRODUCTS_0.productid 
INNER JOIN
    PRODUCTCATS PRODUCTCATS_0 ON PRODUCTS.productcatid = PRODUCTCATS.productcatid 
                AND NOT EXISTS (SELECT SS_1.memid
                                FROM SS AS SS_1  
                                INNER JOIN SSUSED AS SSUSED_1 ON SS_1.ssid = SSUSED_1.ssid 
                                INNER JOIN MEMBERS AS MEMBERS_1 ON SS_1.memid = MEMBERS_1.memid 
                                INNER JOIN PRODUCTS AS PRODUCTS_1 ON SS_1.productid = PRODUCTS_1.productid 
                                INNER JOIN PRODUCTCATS AS PRODUCTCATS_1 ON PRODUCTS_1.productcatid = PRODUCTCATS_1.productcatid
                                WHERE (SSUSED_1.usedate BETWEEN @rvStartWeek2 AND @rvEndWeek2) 
                                  AND (PRODUCTS_1.productcatid IN (27, 28, 29, 58, 77, 75, 30, 61, 31, 32, 47, 68)) 
                                  AND (MEMBERS_1.siteid = @rvSite)
                                  AND (SS_0.memid = SS_1.memid) -- Joint main Query and Subquery
                           )
WHERE        
    (SSUSED_0.usedate BETWEEN @rvStartWeek1 AND @rvEndWeek1) 
    AND (PRODUCTS_0.productcatid IN (27, 28, 29, 58, 77, 75, 30, 61, 31, 32, 47, 68)) 
    AND (MEMBERS_0.siteid = @rvSite)
SQL, SQL-сервер, SQL-сервер-2008, SSRS-2008,
Похожие вопросы
Яндекс.Метрика