4

使用 SQL*Plus 生成通过电子邮件发送给客户的列表,例如:

SET MARKUP HTML ON
SPOOL spool.html
SELECT order_number, entry_date, delivery_date, customer_order_number, order_totals_quantity, TRUNC(order_totals_sqm,2), order_totals_net_value FROM orders WHERE entry_date = SYSDATE;

我如何还可以创建一行来显示列出的order_totals字段的总数并使它们与这些字段保持一致?

即,如果我SELECT COUNT()对这些字段进行了单独的处理,它将在前 3 个字段下列出它们,而实际上它们需要位于原始字段的下方SELECT

更新:如果可能的话,这就是我正在寻找的东西。

other columns ... order_totals_quantity | TRUNC(order_totals_sqm,2) | order_totals_net_value
--------------------------------------------------------------------------------------------
                  Total                 | Total                     | Total
4

3 回答 3

0

试试这个[假设您使用的是 oracle]:

SELECT order_number, entry_date, delivery_date, customer_order_number, order_totals_quantity, TRUNC(order_totals_sqm,2), order_totals_net_value,tot.a, tot.b 
FROM orders, (select sum(order_totals_quantity) a, sum(order_totals_net_value ) b from orders WHERE entry_date = SYSDATE) tot 
WHERE entry_date = SYSDATE;
于 2013-11-06T13:39:47.693 回答
0

也许...取决于您想要什么聚合以及表示唯一记录的内容,以免错误地汇总数量。

SELECT order_number, entry_date, delivery_date, customer_order_number, 
  sum(order_totals_quantity), sum(TRUNC(order_totals_sqm,2)), sum(order_totals_net_value)
FROM orders 
WHERE entry_date = SYSDATE;
GROUP BY GROUPING SETS ((order_number, entry_date, delivery_date, customer_order_number),
         ())

找到的示例:http ://www.oracle-base.com/articles/misc/rollup-cube-grouping-functions-and-grouping-sets.php

于 2013-11-06T13:38:23.520 回答
0

当您使用 SQL*Plus 时,有一种使用计算的更简单的方法。这样做的好处是无需在服务器上运行额外的 SQL。这是一个可以适应您的查询的示例:

    BREAK ON report
    COMPUTE SUM LABEL total OF a ON report

    SELECT 1 AS a FROM dual UNION ALL
    SELECT 2 AS a FROM dual UNION ALL
    SELECT 3 AS a FROM dual;

                A
    -------------
                1
                2
                3
    -------------
                6

    3 rows selected.

您也可以使用其他聚合。这是完整文档的链接:COMPUTE

于 2015-12-03T15:41:40.627 回答