oracle 11g 子查询问题
----------------------------
请教高手一个问题:
需求:我有一个产品表t_products ,表中存的是产品id,和金额,还有一个id 对应的产品的名称表t_b_name
想通过子查询实现:产品名称,产品金额,这样一个数据表
在sql中是这样实现的:
select t.Pid ,
(select top1 a.nodename from t_b_name a where a.nodeid=Pid ) 产品名称,
sum(t.price) as 产品金额
from t_products t
group by t.Pid--------------------------
在oracle中没有对应的top 1,
---如下方法查出来的name都是一个产品的名字,比如“打印机”
select t.Pid ,
(select a.nodename from t_b_name a where a.nodeid=Pid and rownum<2 ) 产品名称,
sum(t.price) as 产品金额
from t_products t
group by t.Pid
-------------------------------
用左连接能实现,请教高手,能不能用类似sql server那样的子查询实现,谢谢
----------------------------
请教高手一个问题:
需求:我有一个产品表t_products ,表中存的是产品id,和金额,还有一个id 对应的产品的名称表t_b_name
想通过子查询实现:产品名称,产品金额,这样一个数据表
在sql中是这样实现的:
select t.Pid ,
(select top1 a.nodename from t_b_name a where a.nodeid=Pid ) 产品名称,
sum(t.price) as 产品金额
from t_products t
group by t.Pid--------------------------
在oracle中没有对应的top 1,
---如下方法查出来的name都是一个产品的名字,比如“打印机”
select t.Pid ,
(select a.nodename from t_b_name a where a.nodeid=Pid and rownum<2 ) 产品名称,
sum(t.price) as 产品金额
from t_products t
group by t.Pid
-------------------------------
用左连接能实现,请教高手,能不能用类似sql server那样的子查询实现,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货