【发布时间】:2014-06-06 18:11:04
【问题描述】:
table1
no | date |
J001 | 06 June |
table2
no | code | qty | /// AVGprice | Total
J001 | B001 | 5 | /// 1500 | 7500
J001 | B003 | 7 | /// 1000 | 7000
table3 table4
code | name | AVGPrice no | code | Price
B001 | procc | 1500 M001 | B001 | 1000
B002 | motherboard | 2000 M001 | B002 | 2000
B003 | VGA card | 1000 M002 | B001 | 2000
M002 | B003 | 1000
我从这个查询中得到 AVGprice
select t.code, t.name, t.avg
from (select table3.code, table3.name, (
select avg(table4.price)
from table4
where table4.code=table3.code)as 'avg'
from table3
)as t
我能做出的结果是
no | date | Info
J001| 06 June | ABCDEFG
通过这些查询
select t.no, t.date, t.info
from (select table1.no, table1.date, 'ABCDEFG' as info
from table1
)as t
我想要的结果是
no | date | Info | Total
J001| 06 June | ABCDEFG | 14500 --> from sum of Total
我不知道将我的平均查询放在哪里以及如何对其求和...
【问题讨论】: