我正在尝试显示发票总输出成本的总和:这些是带有表示主键的斜体列的表:客户:
| name | *cust#* |
| -------- | -------------- |
| Radio Spares | c1 |
| Pyramid| c2 |
物品:
| *item#* | iname | price |
| -------- | -------------- | ----------
| i1 | CD | 1 |
| i2 | DVD | 2 |
长期订单:
| *so#* | cust# | item# |
| -------- | -------------- | ----------
| so1 | c1 | i1 |
| so2 | c2 | i2 |
发票:
| *in#* | cust# |
| -------- | -------------- |
| i1 | c1 |
| i2 | c2 |
送货:
| *d#* | in# |
| -------- | -------------- |
| d1 | 1 |
| d2 | 2 |
| d3 | 1 |
| d4 | 2 |
| d5 | 1 |
| d6 | 2 |
数量:
| so# | d# | quantity |
| -------- | -------------- | -----|
| d1 | 1 | 1|
| d2 | 2 | 2|
| d3 | 1 | 1|
| d4 | 2 | 2|
| d5 | 1 | 1|
| d6 | 2 | 2|
我想找到:请求输出之后的总成本总和:
distinct cu.name as customer_name,
dq.d# as delivery_no,
item.item# as item_no,
item.iname as description,
dq.quantity as quantity,
item.price as item_price,
item.price*dq.quantity as cost,
sum(item.price*dq.quantity) as sum
from customer cu
inner join standingorder sor on cu.cust#=sor.cust#
inner join dquantity dq on sor.order#=dq.order#
inner join invoice iv on cu.cust#=iv.cust#
inner join delivery dl on iv.inv#=dl.inv#
inner join item on sor.item#=item.item#
where cu.cust# = 'c2';
但是当我这样做时,我得到了 ORA-00937: not a single-group group function。但如果我删除
sum(item.price*dq.quantity) as sum
它运行但没有我需要的总和。所以在这种情况下:其中 cu.cust# = 'c1' 的总和为 3,而 'c2' 的总和为 12。
我想看到的:对于c2:
CUSTOMER_NAME DELIVE ITEM_N IName QUANTITY
------------------------ ------ ------ -------------------- ----------
ITEM_PRICE COST
---------- ----------
Pyramid D2 I2 DVD 2
2 4
D4 I2 DVD 2
2 4
D6 I2 DVD 2
2 4
Sum
---
12