3

我正在使用 Firebird 2.1 来执行这个查询:

SELECT DISTINCT INVOICES.INVNO,INVOICES.DEPNO,INVOICES.INVN,INVOICES.CONTNO,SYSPROF.NAME
FROM INVOICES
LEFT JOIN INVSPEC ON (INVOICES.INVNO = INVSPEC.INVNO) AND (INVOICES.DEPNO = INVSPEC.DEPNO)
LEFT JOIN SYSPROF ON (INVSPEC.SYSNO = SYSPROF.SYSNO) WHERE
(INVOICES.INVNO = 17 AND INVOICES.DEPNO = 6555)
OR(INVOICES.INVNO = 16 AND INVOICES.DEPNO = 6555);

它返回给我这些记录:

在此处输入图像描述

请帮助我构建一个将返回这些记录的查询:

在此处输入图像描述

谢谢!

4

1 回答 1

0

例如:

SELECT INVOICES.INVNO,min(INVOICES.DEPNO),min(INVOICES.INVN),min(INVOICES.CONTNO),min(SYSPROF.NAME)
FROM INVOICES
LEFT JOIN INVSPEC ON (INVOICES.INVNO = INVSPEC.INVNO) AND (INVOICES.DEPNO = INVSPEC.DEPNO)
LEFT JOIN SYSPROF ON (INVSPEC.SYSNO = SYSPROF.SYSNO) WHERE
(INVOICES.INVNO = 17 AND INVOICES.DEPNO = 6555)
OR(INVOICES.INVNO = 16 AND INVOICES.DEPNO = 6555);
GROUP BY INVOICES.INVNO

此查询为每张发票返回一行,并从 sysprof 中获取任何名称。

于 2012-09-04T05:28:28.100 回答