select b.code,name,money from a,b where a.code(+)=b.code
a.code(+)=b.code b表的所有项都显示出来,不符合条件的字段为空
我试了 不过我这a表中code不是唯一的,而b表中code是唯一的,如果a表为 a:code money 1 10 2 20 2 30 4 50 4 60 我想按照code分组求sum(money),(select b.code,name,sum(money) from a,b where a.code(+)=b.code group by b.code,name) 这样写好像还是不能列出code=3的列,不知道该怎么写,谢谢!
select b.code,name,money from (select code,sum(money) money from aa group by code) c,b where c.code(+) = b.code
使用外連接就可以了,如樓上幾位所說 外部联接"+"的用法 外部联接"+"按其在"="的左边或右边分左联接和右联接.若不带"+"运算符的表中的一个行不直接匹配于带"+"预算符的表中的任何行,则前者的行与后者中的一个空行相匹配并被返回.若二者均不带’+’,则二者中无法匹配的均被返回.利用外部联接"+",可以替代效率十分低下的 not in 运算,大大提高运行速度.例如,下面这条命令执行起来很慢 select a.empno from emp a where a.empno not in (select empno from emp1 where job=’SALE’); 倘若利用外部联接,改写命令如下: select a.empno from emp a ,emp1 b where a.empno=b.empno(+) and b.empno is null and b.job=’SALE’; 可以发现,运行速度明显提高.
b:code name kind 1 a 1 2 b 1 3 c 1 4 d 2 5 e 2 6 f 2想列出b表中kind=1的所有code的项,和求sum(money) 想象的结果为下: code name sum(money) 1 a 30 2 b 20 3 c 应该怎么写,谢谢!(select b.code,name,sum(money) from a,b where a.code(+)=b.code and kind='1' group by b.code,name) 这样写还是不能列出code=3的项
select b.code,name,money from (select code,sum(money) money from aa group by code) c,b where c.code(+) =bb.code and b.kind=1
SQL> select bb.code,name,money 2 from (select code,sum(money) money from aa group by code) c,bb 3 where c.code(+) =bb.code and bb.kind='1';CODE NAME MONEY ---------- ---------- ---------- 1 a 30 2 b 20 3 c怎么会不行呢?这里aa就是你的a,bb就是你的b
SQL> select bb.code,name,sum(money) 2 from aa,bb 3 where aa.code(+)=bb.code and kind='1' 4 group by bb.code,name;CODE NAME SUM(MONEY) ---------- ---------- ---------- 1 a 30 2 b 20 3 c
b表的所有项都显示出来,不符合条件的字段为空
a:code money
1 10
2 20
2 30
4 50
4 60
我想按照code分组求sum(money),(select b.code,name,sum(money) from a,b where a.code(+)=b.code group by b.code,name) 这样写好像还是不能列出code=3的列,不知道该怎么写,谢谢!
from (select code,sum(money) money from aa group by code) c,b
where c.code(+) = b.code
外部联接"+"的用法 外部联接"+"按其在"="的左边或右边分左联接和右联接.若不带"+"运算符的表中的一个行不直接匹配于带"+"预算符的表中的任何行,则前者的行与后者中的一个空行相匹配并被返回.若二者均不带’+’,则二者中无法匹配的均被返回.利用外部联接"+",可以替代效率十分低下的 not in 运算,大大提高运行速度.例如,下面这条命令执行起来很慢 select a.empno from emp a where a.empno not in (select empno from emp1 where job=’SALE’); 倘若利用外部联接,改写命令如下: select a.empno from emp a ,emp1 b where a.empno=b.empno(+) and b.empno is null and b.job=’SALE’; 可以发现,运行速度明显提高.
a:code money
1 10
1 20
2 20
4 50
6 80
b:code name kind
1 a 1
2 b 1
3 c 1
4 d 2
5 e 2
6 f 2想列出b表中kind=1的所有code的项,和求sum(money)
想象的结果为下:
code name sum(money)
1 a 30
2 b 20
3 c
应该怎么写,谢谢!(select b.code,name,sum(money) from a,b where a.code(+)=b.code and kind='1' group by b.code,name) 这样写还是不能列出code=3的项
from (select code,sum(money) money from aa group by code) c,b
where c.code(+) =bb.code and b.kind=1
2 from (select code,sum(money) money from aa group by code) c,bb
3 where c.code(+) =bb.code and bb.kind='1';CODE NAME MONEY
---------- ---------- ----------
1 a 30
2 b 20
3 c怎么会不行呢?这里aa就是你的a,bb就是你的b
2 from aa,bb
3 where aa.code(+)=bb.code and kind='1'
4 group by bb.code,name;CODE NAME SUM(MONEY)
---------- ---------- ----------
1 a 30
2 b 20
3 c