0
SELECT ORG.DESCRIPTION, ORG.EXTERNALKEY,
   (SELECT P.VALUE FROM PROPERTY P, ORGANIZATION ORG WHERE P.IDX=24 AND ORG.ID=P.ID AND ORG.EXTERNALKEY='200004') AS COR_ACCOUNT,
   (SELECT ORG.DESCRIPTION FROM ORGANIZATION ORG WHERE ORG.NAME = P.VALUE) AS CPC,
   (SELECT P.VALUE FROM PROPERTY P, ORGANIZATION ORG WHERE P.IDX = 4 AND P.ID = ORG.ID AND ORG.EXTERNALKEY = '200004') AS VOEN
FROM PROPERTY P, ORGANIZATION ORG
WHERE P.IDX = 22 AND ORG.EXTERNALKEY = '200004' AND P.ID = ORG.ID;

やあ。このSQLを最適化する方法、またはこれは正常ですか?

4

2 に答える 2

0

あなたの正確な要件はわかりませんが、SQLを考えると、以下が機能するはずです。

SELECT ORG.DESCRIPTION, ORG.EXTERNALKEY,
CASE WHEN P.IDX = 24 then P.Value END AS COR_ACCOUNT,
(SELECT ORG.DESCRIPTION FROM ORGANIZATION ORG WHERE ORG.NAME = P.VALUE) AS CPC,
  CASE WHEN p.idx = 4 then P.VALUE END AS VOEN
FROM PROPERTY P, ORGANIZATION ORG
WHERE P.IDX in(22,24,4) AND ORG.EXTERNALKEY = '200004' AND P.ID = ORG.ID;
于 2012-09-04T10:48:40.987 に答える
0

クエリを最適化します

SELECT ORG.DESCRIPTION,ORG.EXTERNALKEY,
CASE WHEN ORG.EXTERNALKEY='200004' AND P.IDX=24 THEN P.VALUE END AS COR_ACCOUNT,
(SELECT ORG.DESCRIPTION FROM ORGANIZATION ORG WHERE ORG.NAME = P.VALUE) AS CPC,
CASE WHEN ORG.EXTERNALKEY='200004' AND P.IDX=4 THEN P.VALUE END AS VOEN,
FROM PROPERTY P, ORGANIZATION ORG
WHERE P.IDX = 22 AND ORG.EXTERNALKEY = '200004' AND P.ID = ORG.ID;
于 2013-09-02T12:23:23.693 に答える