0

我需要一点帮助。我有两张我知道需要加入的表,这不是问题。我需要显示的是发票中购买的所有产品的发票编号、发票日期和总美元金额。信息需要按发票编号降序排列,然后按发票日期升序排列。到目前为止,我所拥有的并且正在引发错误的是:

SELECT          LINE.INV_NUMBER, 
                INVOICE.INV_DATE, 
                SUM(LINE.LINE_PRICE) 
           FROM LINE 
FULL OUTER JOIN INVOICE ON LINE.INV_NUMBER=INVOICE.INV_NUMBER 
       GROUP BY LINE.INV_NUMBER 
       ORDER BY LINE.INV_NUMBER DESC, 
                INVOICE.INV_DATE ASC;

在我拔出所有头发之前,我们将不胜感激。

更新:

我已将我的声明更新为:

SELECT LINE.INV_NUMBER AS "Line Number", 
       INVOICE.INV_DATE AS "Invoice Date", 
       SUM(LINE.LINE_PRICE) AS "Total Sales" 
  FROM INVOICE FULL OUTER JOIN LINE ON INVOICE.INV_NUMBER=LINE.INV_NUMBER 
 GROUP BY LINE.INV_NUMBER, INVOICE.INV_DATE
 ORDER BY LINE.INV_NUMBER DESC, INVOICE.INV_DATE ASC;

我得到的是数据而不是错误。我现在遇到的问题是我需要按发票编号按降序读取数据,按发票日期按升序读取,所以我假设我需要两个数据输出。我该怎么做?

4

3 回答 3

0

我相信只有那些在 group by 中使用的列才能在 select 子句中检索到。

可能您需要包含 INV_DATE、LINE_PRICE,然后在 select 子句中检索它们的聚合。

参考 java2s.com 中的几个分组示例,这是一个有用的站点。

问候, 斯里哈里

于 2013-11-02T21:07:31.833 回答
0

尝试GROUP BY LINE.INV_NUMBER, INVOICE.INV_DATE

根据您使用的 DBMS,它可能是也可能不是问题。

于 2013-11-02T21:09:50.970 回答
0
SELECT LINE.INV_NUMBER AS "Line Number", 
       INVOICE.INV_DATE AS "Invoice Date", 
       SUM(LINE.LINE_PRICE) AS "Total Sales" 
  FROM INVOICE FULL OUTER JOIN LINE ON INVOICE.INV_NUMBER=LINE.INV_NUMBER 
 GROUP BY LINE.INV_NUMBER, INVOICE.INV_DATE
 ORDER BY INVOICE.INV_DATE ASC, LINE.INV_NUMBER DESC;
于 2014-10-13T15:05:43.663 回答