作者erho (ptt访客)
看板Database
标题Re: [SQL ] 请问有没有SQL语法可表达这种查询结果
时间Wed May 21 16:27:38 2008
※ 引述《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