Re: [SQL ] 請問有沒有SQL語法可表達這種查詢結果
※ 引述《erho (ptt訪客)》之銘言:
: 資料庫是oracle
: 有3個table
: table1
: ------
: code(pk) 產品代碼
: name 產品名稱
: kind_no 該產品分類代碼
: table2
: ------
: kind_no(pk) 分類代碼
: kind_name 分類名稱
: table3
: ------
: seq_no(pk) 序號
: keyindate 輸入日期
: code 產品代碼
: qty 數量
: price 金額
: 如果我要查詢
: 查詢結果
: -------
: kind_name
: Tprice(該分類金額的總合)
: 請問要SQL語法要怎麼表達
可是我參考我以前的發文我還是寫不出來
我的想法是
先寫成2個語法
分類
select table1.code,table2.kind_name
from table1,table2 where
table1.kind_no=table2.kind_no;
統計
select table3.code,sum(tqty), sum(amt) from table3
where keyindate between 0970101 and 0970131 group by code;
然後我這樣寫
select A.table2.kind_name,B.sum(tqty),B.sum(amt)
from
(select table1.code,table2.kind_name
from table1,table2 where
table1.kind_no=table2.kind_no) A,
(select table3.code,sum(tqty), sum(amt) from table3
where keyindate between 0970101 and 0970131 group by code) B
where A.table1.code=B.table3.code
group by A.table2.kind_name;
但是這樣寫oracle回應ORA-00904:invalid identifier
請問我的寫法到底出了什麼問題
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.127.134.223
討論串 (同標題文章)