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 回答