需要将总订单数添加到摘要查询中

时间:2016-03-14 11:48:45

标签: sql db2 db2-400

在下文中,我需要在此处添加每个订单类型的订单总数,即IHORDT。我试过count(t01.ihordt),但它不是有效的。我需要此订单总数才能获得每个订单的平均金额。

预计数据:

电流:

pull

新变化:添加到上面的一列:

IHORDT   current year     previous year
RTR      100,000             90,000
INT      2,000,000           1,500,000

1 个答案:

答案 0 :(得分:0)

要接收组中的记录计数,您需要使用count(*)

所以这是一个通用的例子:

select order_type, 
       sum(order_amount) as total_sales, 
       count(*) as number_of_orders
  from order_header
  group by order_type;