0
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
我不知道從哪裏把我的平均查詢,如何總結這...
我添加了平均值的總和,但這可能不是你想要的。你可以把它改成你想在那裏總結的內容。 –
未知的列表3 ....我應該把它 - >從表4,表3?並且總和...它與第一avg 1500顯示相同,不像2500其中B001和B003的avgprice的總和 – user3651460