1

派生テーブルを使用した次の SQL クエリがあり、そのため、インデックス付きビューの CLUSTERED INDEX を作成できません。したがって、派生テーブルを通常の結合に変換する必要があります。

SELECT
......
FROM 
dbo.invoice i

LEFT JOIN 
(
    SELECT SUM(amount) as servicesamount
    ,ise.invoiceuid
    ,ise.episodeuid
    ,ise.memberuid
    ,ev.caseuid

    FROM dbo.invoice_services ise
    JOIN dbo.invoice inv on inv.invoiceuid = ise.invoiceuid
    JOIN dbo.event ev ON ev.eventuid = ise.episodeuid -- JOIN IN ORDER TO BRING EVENT INVOCIES ONLY (DENTAL INVOICES COULD EXIST)
    GROUP BY ise.invoiceuid,ise.episodeuid,ise.memberuid,ev.caseuid

) ise ON ise.invoiceuid = i.invoiceuid

変換方法の手がかり

LEFT JOIN 
    (
        SELECT SUM(amount) as servicesamount
        ,ise.invoiceuid
        ,ise.episodeuid
        ,ise.memberuid
        ,ev.caseuid

        FROM dbo.invoice_services ise
        JOIN dbo.invoice inv on inv.invoiceuid = ise.invoiceuid
        JOIN dbo.event ev ON ev.eventuid = ise.episodeuid -- JOIN IN ORDER TO BRING EVENT INVOCIES ONLY (DENTAL INVOICES COULD EXIST)
        GROUP BY ise.invoiceuid,ise.episodeuid,ise.memberuid,ev.caseuid

    ) ise

通常加入するには?

感謝します!!

4

1 に答える 1

0

あなたはこれを試すことができます

SELECT ...
  ,SUM(amount) as servicesamount
  ,ise.invoiceuid
  ,ise.episodeuid
  ,ise.memberuid
  ,ev.caseuid
  ,...
FROM dbo.invoice inv 
 LEFT JION dbo.invoice_services ise ON inv.invoiceuid = ise.invoiceuid
 LEFT JOIN dbo.event ev ON ev.eventuid = ise.episodeuid
GROUP BY inv..., ise.invoiceuid,ise.episodeuid,ise.memberuid,ev.caseuid
于 2013-02-26T09:03:50.310 に答える