0

我需要将这两个查询合并为一个查询。Keyfield1 和 TPOLNO 应该是连接字段。我将如何做这个单一的查询?

SELECT TPOLNO, SUM(TTSAMT) AS SUM FROM PFPOSTR410 WHERE 
((TTRNYY=2012 AND TTRNMM=3 AND TTRNDD>=27) OR (TTRNYY=2012 AND TTRNMM>3) OR 
(TTRNYY=2013 AND TTRNMM<=2) OR (TTRNYY=2013 AND TTRNMM=3 AND TTRNDD<=27)) 
GROUP BY TPOLNO HAVING SUM(TTSAMT)>=5000 ORDER BY TPOLNO ASC

SELECT KEYFIELD1, KEYFROBJ FROM CMRELATN WHERE RELROLETC=8

提前感谢任何方向!

  • 乔什
4

1 回答 1

-1

If i understand your questions, you need to do a simple inner join of the 2 tables:

SELECT TPOLNO, SUM(TTSAMT) AS SUM, KEYFIELD1, KEYFROBJ
FROM PFPOSTR410, CMRELATN 
WHERE 
    ((TTRNYY=2012 AND TTRNMM=3 AND TTRNDD>=27) OR (TTRNYY=2012 AND TTRNMM>3) OR 
(TTRNYY=2013 AND TTRNMM<=2) OR (TTRNYY=2013 AND TTRNMM=3 AND TTRNDD<=27))
    AND KEYFIELD1=TPOLNO
    AND RELROLETC=8
GROUP BY TPOLNO, KEYFIELD1, KEYFROBJ
HAVING SUM(TTSAMT)>=5000
ORDER BY TPOLNO ASC
于 2013-05-06T14:13:34.317 回答