使用 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
最佳答案
也许...
取决于您想要什么聚合以及什么表示唯一记录,以免错误地求和数量。
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
关于sql - 使用 SQL*Plus 从以前的 SELECT 中选择总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19813291/